diff --git a/.github/build-v2-wip.yaml b/.github/build-v2-wip.yaml deleted file mode 100644 index ed7bf37..0000000 --- a/.github/build-v2-wip.yaml +++ /dev/null @@ -1,173 +0,0 @@ -# -# -# This is work in progress! Goal: parallelize builds and cache docker layers. Ideally not rebuild images that have no changed commits, -# e.g. version each component separately vs. versioning all in one package based on workspaces-stack's version. -# -# - - -name: "Release v2" -on: - workflow_dispatch: - inputs: - environment: - description: 'Environment' - required: true - default: 'dev' - -jobs: - build: - runs-on: ubuntu-latest - name: Build, Push, Deploy - environment: "dev" - timeout-minutes: 45 - steps: - - uses: actions/checkout@v2 - with: - submodules: recursive - -# - name: Generate release notes -# run: -# ./gen-rel-notes.sh > CHANGELOG - - - name: Set commit SHA as code version - run: echo "CODE_VERSION=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV - - - uses: docker/login-action@v3 - with: - registry: ${{ vars.WS_DOCKER_REGISTRY }} - username: ${{ vars.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - uses: docker/setup-buildx-action@v3 - name: Set up Docker Buildx - - - name: Build frontend - uses: docker/build-push-action@v6 - with: - context: ./frontend - push: true - tags: ${{ vars.WS_DOCKER_REGISTRY }}/workspaces-frontend:${{ vars.ENV }}, ${{ vars.WS_DOCKER_REGISTRY }}/workspaces-frontend:${{ env.CODE_VERSION }} - cache-from: type=gha - cache-to: type=gha,mode=max - - - name: Build osm-cgimap - uses: docker/build-push-action@v6 - with: - context: ./osm-cgimap - push: true - file: ./osm-cgimap/docker/ubuntu/Dockerfile2404 - tags: ${{ vars.WS_DOCKER_REGISTRY }}/workspaces-osm-cgimap:${{ vars.ENV }}, ${{ vars.WS_DOCKER_REGISTRY }}/workspaces-osm-cgimap:${{ env.CODE_VERSION }} - cache-from: type=gha - cache-to: type=gha,mode=max - - - name: Build osm-log-proxy - uses: docker/build-push-action@v6 - with: - context: ./osm-log-proxy - push: true - tags: ${{ vars.WS_DOCKER_REGISTRY }}/workspaces-osm-log-proxy:${{ vars.ENV }}, ${{ vars.WS_DOCKER_REGISTRY }}/workspaces-osm-log-proxy:${{ env.CODE_VERSION }} - cache-from: type=gha - cache-to: type=gha,mode=max - - - name: Build osm-rails - uses: docker/build-push-action@v6 - with: - context: ./osm-rails - push: true - file: ./osm-rails/Dockerfile.prod - tags: ${{ vars.WS_DOCKER_REGISTRY }}/workspaces-osm-rails:${{ vars.ENV }}, ${{ vars.WS_DOCKER_REGISTRY }}/workspaces-osm-rails:${{ env.CODE_VERSION }} - cache-from: type=gha - cache-to: type=gha,mode=max - - - name: Build osm-web - uses: docker/build-push-action@v6 - with: - context: ./osm-web - push: true - tags: ${{ vars.WS_DOCKER_REGISTRY }}/workspaces-osm-web:${{ vars.ENV }}, ${{ vars.WS_DOCKER_REGISTRY }}/workspaces-osm-web:${{ env.CODE_VERSION }} - cache-from: type=gha - cache-to: type=gha,mode=max - - - name: Build pathways-editor - uses: docker/build-push-action@v6 - with: - context: ./pathways-editor - push: true - tags: ${{ vars.WS_DOCKER_REGISTRY }}/workspaces-pathways-editor:${{ vars.ENV }}, ${{ vars.WS_DOCKER_REGISTRY }}/workspaces-pathways-editor:${{ env.CODE_VERSION }} - cache-from: type=gha - cache-to: type=gha,mode=max - - - name: Build rapid - uses: docker/build-push-action@v6 - with: - context: ./rapid - push: true - tags: ${{ vars.WS_DOCKER_REGISTRY }}/workspaces-rapid:${{ vars.ENV }}, ${{ vars.WS_DOCKER_REGISTRY }}/workspaces-rapid:${{ env.CODE_VERSION }} - cache-from: type=gha - cache-to: type=gha,mode=max - - - name: Build tasks-backend - uses: docker/build-push-action@v6 - with: - context: ./tasking-manager - push: true - file: ./tasking-manager/scripts/docker/Dockerfile.backend - target: prod - build-args: | - APP_UID=1000 - tags: ${{ vars.WS_DOCKER_REGISTRY }}/workspaces-tasks-backend:${{ vars.ENV }}, ${{ vars.WS_DOCKER_REGISTRY }}/workspaces-tasks-backend:${{ env.CODE_VERSION }} - cache-from: type=gha - cache-to: type=gha,mode=max - - - name: Build tasks-frontend - uses: docker/build-push-action@v6 - with: - context: ./tasking-manager - push: true - file: ./tasking-manager/scripts/docker/Dockerfile.frontend - build-args: | - TM_APP_API_URL="https://tasks.workspaces-${{ vars.ENV }}.sidewalks.washington.edu/" - tags: ${{ vars.WS_DOCKER_REGISTRY }}/workspaces-tasks-frontend:${{ vars.ENV }}, ${{ vars.WS_DOCKER_REGISTRY }}/workspaces-tasks-frontend:${{ env.CODE_VERSION }} - cache-from: type=gha - cache-to: type=gha,mode=max - - - name: Deploy - env: - ENV: ${{ vars.ENV }} - WS_DOCKER_REGISTRY: ${{ vars.WS_DOCKER_REGISTRY }} - - # machine to deploy to - AZURE_DOCKER_HOST_IP: ${{ vars.AZURE_DOCKER_HOST_IP }} - - # tag to deploy - WS_DOCKER_TAG: ${{ env.CODE_VERSION }} - - # passwords - WS_API_DB_PASS: ${{ secrets.WS_API_DB_PASS }} - WS_MAPBOX_ACCESS_TOKEN: ${{ secrets.WS_MAPBOX_ACCESS_TOKEN }} - WS_OSM_DB_PASS: ${{ secrets.WS_OSM_DB_PASS }} - WS_OSM_SECRET_KEY_BASE: ${{ secrets.WS_OSM_SECRET_KEY_BASE }} - WS_SMTP_PASS: ${{ secrets.WS_SMTP_PASS }} - WS_TASKS_DB_PASS: ${{ secrets.WS_TASKS_DB_PASS }} - WS_TASKS_SECRET_KEY: ${{ secrets.WS_TASKS_SECRET_KEY }} - run: | - mkdir -p ~/.ssh - eval `ssh-agent -s` - - ssh-keyscan ${{ vars.AZURE_DOCKER_HOST_IP }} >> ~/.ssh/known_hosts - - echo "${{ secrets.GH_ACTIONS_SSH_KEY }}" > ~/.ssh/github_actions - chmod 600 ~/.ssh/github_actions - ssh-add ~/.ssh/github_actions - - docker context create dev --docker "host=ssh://github-actions@${{ vars.AZURE_DOCKER_HOST_IP }}" - docker context use dev - - # remove images no longer in use--may need disk space to pull - docker image prune -a -f - - # pull new images, recreate containers - docker compose -f docker-compose.deploy.yml --env-file tdei_uw.env up -d --force-recreate --remove-orphans - - \ No newline at end of file diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 550b66a..a740306 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,5 +1,10 @@ name: "Release" on: + push: + branches: + - dev + - stage + workflow_dispatch: inputs: build_flag: @@ -13,9 +18,9 @@ on: jobs: build: runs-on: ubuntu-latest - name: Build, Push, Deploy (dev) - environment: "dev" - timeout-minutes: 45 + name: Build, Push, Deploy + environment: ${{ github.ref_name }} + timeout-minutes: 20 steps: - uses: actions/checkout@v2 with: @@ -31,9 +36,9 @@ jobs: id: build_changelog uses: mikepenz/release-changelog-builder-action@v5 with: - fromTag: "0.1" toTag: ${{ github.sha }} mode: "HYBRID" + outputFile: "CHANGELOG.md" - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -56,6 +61,9 @@ jobs: WS_TASKS_DB_PASS: ${{ secrets.WS_TASKS_DB_PASS }} WS_TASKS_SECRET_KEY: ${{ secrets.WS_TASKS_SECRET_KEY }} + - name: Print CHANGELOG.md + run: cat CHANGELOG.md + - name: Deploy env: ENV: ${{ vars.ENV }} @@ -88,8 +96,8 @@ jobs: ssh-add ~/.ssh/github_actions echo Configuring docker context - docker context create dev --docker "host=ssh://github-actions@${{ vars.AZURE_DOCKER_HOST_IP }}" - docker context use dev + docker context create ${{ vars.ENV }} --docker "host=ssh://github-actions@${{ vars.AZURE_DOCKER_HOST_IP }}" + docker context use ${{ vars.ENV }} # remove images no longer in use--may need disk space to pull echo Pruning old docker images diff --git a/README.md b/README.md index cc360df..ae02f7a 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ ```docker-compose -f docker-compose.build.yml --env-file XXX.env build``` -```docker-compose --env-file XXX.env push``` +```docker-compose -f docker-compose.build.yml push``` Replace XXX.env with the environment definition file of the environment for which you want to build an image. This can be overridden when running (see below). @@ -37,3 +37,7 @@ Replace XXX.env with the environment definition file of the environment for whic * ```example.env```: template of the .env file required by the Docker compose YAML files * ```tdei_uw.env```: .env for deployment at UW's TDEI center. Only UW should use this, new users should adapt example.env to suit their needs. LTG: remove this file from this repo. + +# GH Actions + +See GitHub's actions tab in this repo for more deployment examples/steps. \ No newline at end of file diff --git a/docker-buildx.build.hcl b/docker-buildx.build.hcl deleted file mode 100644 index 42a05da..0000000 --- a/docker-buildx.build.hcl +++ /dev/null @@ -1,201 +0,0 @@ -group "default" { - targets = [ - "osm-web", - "pathways-editor", - "rapid", - "osm-cgimap", - "frontend", - "tasks-frontend", - "tasks-backend", - "osm-log-proxy", - "osm-rails" - ] -} - -variable "WS_DOCKER_REGISTRY" { - default = "opensidewalksdev.azurecr.io" -} - -variable "ENV" { - default = "dev" -} - -variable "CODE_VERSION" { - default = "0" -} - -variable "VITE_API_URL" { - default = "https://api.workspaces-${ENV}.sidewalks.washington.edu/api/v1/" -} - -variable "VITE_OSM_URL" { - default = "https://osm.workspaces-${ENV}.sidewalks.washington.edu/" -} - -variable "VITE_PATHWAYS_EDITOR_URL" { - default = "https://pathways.workspaces-${ENV}.sidewalks.washington.edu/" -} - -variable "VITE_RAPID_URL" { - default = "https://rapid.workspaces-${ENV}.sidewalks.washington.edu/" -} - -variable "VITE_TDEI_API_URL" { - default = "https://tdei-api-${ENV}.azurewebsites.net/api/v1/" -} - -variable "VITE_TDEI_USER_API_URL" { - default = "https://tdei-usermanagement-be-${ENV}.azurewebsites.net/api/v1/" -} - -target "frontend" { - context = "frontend" - dockerfile = "Dockerfile" -# args = { -# CODE_VERSION = ${CODE_VERSION} -# VITE_API_URL = ${VITE_API_URL} -# VITE_OSM_URL = ${VITE_OSM_URL} -# VITE_PATHWAYS_EDITOR_URL = ${VITE_PATHWAYS_EDITOR_URL} -# VITE_RAPID_URL = ${VITE_RAPID_URL} -# VITE_TDEI_API_URL = ${VITE_TDEI_API_URL} -# VITE_TDEI_USER_API_URL = ${VITE_TDEI_USER_API_URL} -# } - tags = [ - "${WS_DOCKER_REGISTRY}/workspaces-frontend:${ENV}", - "${WS_DOCKER_REGISTRY}/workspaces-frontend:${CODE_VERSION}" - ] - cache-to = [ - "type=gha" - ] - cache-from = [ - "type=gha" - ] - -} - -target "osm-cgimap" { - context = "osm-cgimap" - dockerfile = "docker/ubuntu/Dockerfile2404" - tags = [ - "${WS_DOCKER_REGISTRY}/workspaces-osm-cgimap:${ENV}", - "${WS_DOCKER_REGISTRY}/workspaces-osm-cgimap:${CODE_VERSION}" - ] - cache-to = [ - "type=gha" - ] - cache-from = [ - "type=gha" - ] -} - -target "osm-log-proxy" { - context = "osm-log-proxy" - dockerfile = "Dockerfile" - tags = [ - "${WS_DOCKER_REGISTRY}/workspaces-osm-log-proxy:${ENV}", - "${WS_DOCKER_REGISTRY}/workspaces-osm-log-proxy:${CODE_VERSION}" - ] - cache-to = [ - "type=gha" - ] - cache-from = [ - "type=gha" - ] -} - -target "osm-rails" { - context = "osm-rails" - dockerfile = "Dockerfile.prod" - tags = [ - "${WS_DOCKER_REGISTRY}/workspaces-osm-rails:${ENV}", - "${WS_DOCKER_REGISTRY}/workspaces-osm-rails:${CODE_VERSION}" - ] - cache-to = [ - "type=gha" - ] - cache-from = [ - "type=gha" - ] -} - -target "osm-web" { - context = "osm-web" - dockerfile = "Dockerfile" - tags = [ - "${WS_DOCKER_REGISTRY}/workspaces-osm-web:${ENV}", - "${WS_DOCKER_REGISTRY}/workspaces-osm-web:${CODE_VERSION}" - ] - cache-to = [ - "type=gha" - ] - cache-from = [ - "type=gha" - ] -} - -target "pathways-editor" { - context = "pathways-editor" - dockerfile = "Dockerfile" - tags = [ - "${WS_DOCKER_REGISTRY}/workspaces-pathways-editor:${ENV}", - "${WS_DOCKER_REGISTRY}/workspaces-pathways-editor:${CODE_VERSION}" - ] - cache-to = [ - "type=gha" - ] - cache-from = [ - "type=gha" - ] -} - -target "rapid" { - context = "rapid" - dockerfile = "Dockerfile" - tags = [ - "${WS_DOCKER_REGISTRY}/workspaces-rapid:${ENV}", - "${WS_DOCKER_REGISTRY}/workspaces-rapid:${CODE_VERSION}" - ] - cache-to = [ - "type=gha" - ] - cache-from = [ - "type=gha" - ] -} - -target "tasks-backend" { - context = "tasking-manager" - dockerfile = "./scripts/docker/Dockerfile.backend" - tags = [ - "${WS_DOCKER_REGISTRY}/workspaces-tasks-backend:${ENV}", - "${WS_DOCKER_REGISTRY}/workspaces-tasks-backend:${CODE_VERSION}" - ] - target = "prod" - args = { - APP_UID = "1000" - } - cache-to = [ - "type=gha" - ] - cache-from = [ - "type=gha" - ] -} - -target "tasks-frontend" { - context = "tasking-manager" - dockerfile = "./scripts/docker/Dockerfile.frontend" - tags = [ - "${WS_DOCKER_REGISTRY}/workspaces-tasks-frontend:${ENV}", - "${WS_DOCKER_REGISTRY}/workspaces-tasks-frontend:${CODE_VERSION}" - ] - args = { - TM_APP_API_URL = "https://tasks.workspaces-${ENV}.sidewalks.washington.edu/" - } - cache-to = [ - "type=gha" - ] - cache-from = [ - "type=gha" - ] -} \ No newline at end of file