From 4ed0576674034255b4730def87cdc47ce5108afa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Honeiser?= Date: Tue, 7 Feb 2023 15:35:01 +0100 Subject: [PATCH] chore(ci/cd): update gha pipeline for flux2 --- .github/workflows/cd.yaml | 64 ++++++++++++++++++-------- .github/workflows/ci.yaml | 20 ++++++-- .github/workflows/manual_delivery.yaml | 48 +++++++++++++------ discourse-dev.yml | 21 +++++---- discourse-prod.yml | 21 +++++---- discourse-stage.yml | 21 +++++---- 6 files changed, 127 insertions(+), 68 deletions(-) diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml index ad8448c..f28115b 100644 --- a/.github/workflows/cd.yaml +++ b/.github/workflows/cd.yaml @@ -2,34 +2,40 @@ name: Delivery & Release (Docker Build, Tag & Push) on: push: - branches: [master] + branches: + - master + release: - types: [released] + types: + - released jobs: prepare: runs-on: ubuntu-latest outputs: - ENV: ${{ steps.tag.outputs.env }} - TAG: ${{ steps.tag.outputs.tag }} + ENV: ${{ steps.tag.outputs.ENV }} + TAG: ${{ steps.tag.outputs.CI_COMMIT_SHORT_SHA }} + steps: - name: Checkout uses: actions/checkout@v2 + - name: Set Tag & Environment id: tag - run: | - export CI_COMMIT_SHORT_SHA=$(git describe --abbrev=7 --always --tags) - echo "::set-output name=tag::$CI_COMMIT_SHORT_SHA" - echo "Commit for this pipeline: "; - echo $CI_COMMIT_SHORT_SHA; - if [ ${GITHUB_REF##*/} = "master" ]; then - export ENV=stage - else - export ENV=prod + run: |- + CI_COMMIT_SHORT_SHA=$(git describe --abbrev=7 --always --tags) + + if [[ ${GITHUB_REF##*/} = "master" ]]; then + ENV=stage + fi - echo "::set-output name=env::$ENV" - echo "Environment for this pipeline: "; - echo $ENV + + echo "CI_COMMIT_SHORT_SHA=${CI_COMMIT_SHORT_SHA}" >> $GITHUB_OUTPUT + echo "ENV=${ENV:-prod}" >> $GITHUB_OUTPUT + + echo "Commit for this pipeline: ${CI_COMMIT_SHORT_SHA}" + echo "Environment for this pipeline: ${ENV:-prod}"; + build-push-promote-image: runs-on: ubuntu-latest needs: prepare @@ -41,13 +47,16 @@ jobs: POSTGRES_PASSWORD: discourse POSTGRES_PORT: 5432 POSTGRES_USER: discourse + ports: - 5432:5432 + options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + redis: image: redis options: >- @@ -59,10 +68,12 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 + - name: Setup Database per CI Environment id: env_databases_setup env: ENV: ${{ needs.prepare.outputs.ENV }} + run: | set -e set -u @@ -71,6 +82,7 @@ jobs: CREATE DATABASE "discourse-$ENV"; GRANT ALL PRIVILEGES ON DATABASE "discourse-$ENV" TO discourse; EOSQL + - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v1 id: configure-aws-creds @@ -78,9 +90,11 @@ jobs: aws-access-key-id: ${{ secrets.ECR_AWS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.ECR_AWS_SECRET_ACCESS_KEY }} aws-region: us-west-2 + - name: Login to Amazon ECR id: login-ecr uses: aws-actions/amazon-ecr-login@v1 + - name: Build and Push Stage Image to ECR id: build-push env: @@ -88,20 +102,32 @@ jobs: ECR_REPOSITORY: discourse ENV: ${{ needs.prepare.outputs.ENV }} TAG: ${{ needs.prepare.outputs.TAG }} + run: | export GHA_NETWORK=$(docker network ls --filter driver=bridge --filter name=github_network_ --format '{{.Name}}') - git clone -q https://github.com/discourse/discourse_docker.git - cd discourse_docker - mkdir -p includes && mkdir -p containers + + git clone https://github.com/discourse/discourse_docker.git && cd discourse_docker + mkdir -p containers includes + cp ../discourse-$ENV.yml containers/app.yml cp ../includes/* includes/ + sed -i "s,environment,$ENV," includes/after_build.yml sed -i "s,gha_bridge_network,$GHA_NETWORK," containers/app.yml + ./launcher bootstrap app + + TIMESTAMP=$(date '+%F.%H%M%S') + + docker tag local_discourse/app:latest ${ECR_REGISTRY}/${ECR_REPOSITORY}:${ENV}-${TIMESTAMP} + docker push ${ECR_REGISTRY}/${ECR_REPOSITORY}:${ENV}-${TIMESTAMP} + docker tag local_discourse/app:latest $ECR_REGISTRY/$ECR_REPOSITORY:$ENV-$TAG docker push $ECR_REGISTRY/$ECR_REPOSITORY:$ENV-$TAG + docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$ENV-$TAG $ECR_REGISTRY/$ECR_REPOSITORY:$ENV-$GITHUB_SHA docker push $ECR_REGISTRY/$ECR_REPOSITORY:$ENV-$GITHUB_SHA + - name: Logut of Amazon ECR if: always() run: docker logout ${{ steps.login-ecr.outputs.registry }} diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4aaa370..5fe814f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -5,7 +5,6 @@ on: branches: - '**' - '!master' - pull_request_target: {} jobs: build-bootstrap-image: @@ -18,13 +17,16 @@ jobs: POSTGRES_PASSWORD: discourse POSTGRES_PORT: 5432 POSTGRES_USER: discourse + ports: - 5432:5432 + options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + redis: image: redis options: >- @@ -35,11 +37,15 @@ jobs: strategy: matrix: - env: ['dev', 'stage', 'prod'] + env: + - dev + - stage + - prod steps: - name: Checkout uses: actions/checkout@v2 + - name: Setup Database per CI Environment id: env_databases_setup run: | @@ -50,15 +56,19 @@ jobs: CREATE DATABASE "discourse-${{ matrix.env }}"; GRANT ALL PRIVILEGES ON DATABASE "discourse-${{ matrix.env }}" TO discourse; EOSQL + - name: Pre-build Image id: prebuild run: | export GHA_NETWORK=$(docker network ls --filter driver=bridge --filter name=github_network_ --format '{{.Name}}') - git clone -q https://github.com/discourse/discourse_docker.git - cd discourse_docker - mkdir -p includes && mkdir -p containers + + git clone https://github.com/discourse/discourse_docker.git && cd discourse_docker + mkdir -p containers includes + cp ../discourse-${{ matrix.env }}.yml containers/app.yml cp ../includes/* includes/ + sed -i "s,environment,${{ matrix.env }}," includes/after_build.yml sed -i "s,gha_bridge_network,$GHA_NETWORK," containers/app.yml + ./launcher bootstrap app diff --git a/.github/workflows/manual_delivery.yaml b/.github/workflows/manual_delivery.yaml index ed32b14..1d67a6f 100644 --- a/.github/workflows/manual_delivery.yaml +++ b/.github/workflows/manual_delivery.yaml @@ -12,22 +12,24 @@ jobs: prepare: runs-on: ubuntu-latest outputs: - ENV: ${{ steps.tag.outputs.env }} - TAG: ${{ steps.tag.outputs.tag }} + ENV: ${{ steps.tag.outputs.ENV }} + TAG: ${{ steps.tag.outputs.CI_COMMIT_SHORT_SHA }} + steps: - name: Checkout uses: actions/checkout@v2 - name: Set Tag id: tag - run: | - export CI_COMMIT_SHORT_SHA=$(git describe --abbrev=7 --always --tags) - echo "::set-output name=tag::$CI_COMMIT_SHORT_SHA" - echo "Commit for this pipeline: "; - echo $CI_COMMIT_SHORT_SHA; - export ENV=${{ github.event.inputs.environment }} - echo "::set-output name=env::$ENV" - echo "Environment for this pipeline: "; - echo $ENV + run: |- + CI_COMMIT_SHORT_SHA=$(git describe --abbrev=7 --always --tags) + ENV=${{ github.event.inputs.environment }} + + echo "CI_COMMIT_SHORT_SHA=${CI_COMMIT_SHORT_SHA}" >> ${GITHUB_OUTPUT} + echo "ENV=${ENV}" >> ${GITHUB_OUTPUT} + + echo "Commit for this pipeline: ${CI_COMMIT_SHORT_SHA}" + echo "Environment for this pipeline: ${ENV}" + build-push-image: runs-on: ubuntu-latest needs: prepare @@ -39,13 +41,16 @@ jobs: POSTGRES_PASSWORD: discourse POSTGRES_PORT: 5432 POSTGRES_USER: discourse + ports: - 5432:5432 + options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + redis: image: redis options: >- @@ -57,10 +62,12 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 + - name: Setup Database per CI Environment id: env_databases_setup env: ENV: ${{ needs.prepare.outputs.ENV }} + run: | set -e set -u @@ -69,6 +76,7 @@ jobs: CREATE DATABASE "discourse-$ENV"; GRANT ALL PRIVILEGES ON DATABASE "discourse-$ENV" TO discourse; EOSQL + - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v1 id: configure-aws-creds @@ -76,9 +84,11 @@ jobs: aws-access-key-id: ${{ secrets.ECR_AWS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.ECR_AWS_SECRET_ACCESS_KEY }} aws-region: us-west-2 + - name: Login to Amazon ECR id: login-ecr uses: aws-actions/amazon-ecr-login@v1 + - name: Build and Push Stage Image to ECR id: build-push env: @@ -88,16 +98,26 @@ jobs: TAG: ${{ needs.prepare.outputs.TAG }} run: | export GHA_NETWORK=$(docker network ls --filter driver=bridge --filter name=github_network_ --format '{{.Name}}') - git clone -q https://github.com/discourse/discourse_docker.git - cd discourse_docker - mkdir -p includes && mkdir -p containers + + git clone https://github.com/discourse/discourse_docker.git && cd discourse_docker + mkdir -p containers includes + cp ../discourse-$ENV.yml containers/app.yml cp ../includes/* includes/ + sed -i "s,environment,$ENV," includes/after_build.yml sed -i "s,gha_bridge_network,$GHA_NETWORK," containers/app.yml + ./launcher bootstrap app + + TIMESTAMP=$(date '+%F.%H%M%S') + + docker tag local_discourse/app:latest ${ECR_REGISTRY}/${ECR_REPOSITORY}:${ENV}-${TIMESTAMP} + docker push ${ECR_REGISTRY}/${ECR_REPOSITORY}:${ENV}-${TIMESTAMP} + docker tag local_discourse/app:latest $ECR_REGISTRY/$ECR_REPOSITORY:$ENV-$TAG docker push $ECR_REGISTRY/$ECR_REPOSITORY:$ENV-$TAG + - name: Logut of Amazon ECR if: always() run: docker logout ${{ steps.login-ecr.outputs.registry }} diff --git a/discourse-dev.yml b/discourse-dev.yml index 9536b09..169828e 100644 --- a/discourse-dev.yml +++ b/discourse-dev.yml @@ -1,3 +1,4 @@ +base_image: discourse/base:2.0.20220818-0047 templates: - "includes/moz.web.template.yml" - "includes/contribute.yml" @@ -23,16 +24,16 @@ hooks: cd: $home/plugins cmd: - mkdir -p plugins - - git clone https://github.com/discourse/discourse-akismet.git - - git clone https://github.com/mozilla/discourse-mozilla-iam.git -b development - - git clone https://github.com/mozilla/discourse-expose-emails-in.git -b development - - git clone https://github.com/mozilla/discourse-post-read-email.git -b development - - git clone https://github.com/discourse/discourse-solved.git - - git clone https://github.com/mozilla/discourse-sidekiq-monitor.git - - git clone https://github.com/mozilla/discourse-mozilla-letter-avatar.git - - git clone https://github.com/mozilla/discourse-auto-email-in -b development - - git clone https://github.com/mozilla/discourse-group-category-notification.git -b development - - git clone https://github.com/mozilla/discourse-mozilla-gcm -b development + - git clone https://github.com/discourse/discourse-akismet; cd discourse-akismet; git checkout 6abd5d252c4435ac5a507d04113b7ff306d833b7 + - git clone https://github.com/mozilla/discourse-mozilla-iam; cd discourse-mozilla-iam; git checkout f66123785a02a67ca10d13649cea00c772f7e40a + - git clone https://github.com/mozilla/discourse-expose-emails-in; cd discourse-expose-emails-in; git checkout e4e92b02bd150c72585eba232a27aa4bf9e7f5fb + - git clone https://github.com/mozilla/discourse-post-read-email; cd discourse-post-read-email; git checkout 0031da69216ba759cbf5cdda4ff4ad818e4a617f + - git clone https://github.com/discourse/discourse-solved; cd discourse-solved; git checkout 30248619e28d5f173c4dfd149d3d8ba39e3b8796 + - git clone https://github.com/mozilla/discourse-sidekiq-monitor; cd discourse-sidekiq-monitor; git checkout 34178b637ea508d2ef103b6d48d2e0c21af155dd + - git clone https://github.com/mozilla/discourse-mozilla-letter-avatar; cd discourse-mozilla-letter-avatar; git checkout a5cc90fdafe523a21b5b54abe63d7798efe77b49 + - git clone https://github.com/mozilla/discourse-auto-email-in; cd discourse-auto-email-in; git checkout ca205f63e8b8852154fddd30bf09c994070727e2 + - git clone https://github.com/mozilla/discourse-group-category-notification; cd discourse-group-category-notification; git checkout 8be0c45e8a19c4c702a8a468e882d9968a967ee9 + - git clone https://github.com/mozilla/discourse-mozilla-gcm; cd discourse-mozilla-gcm; git checkout 1d15d63e6dca4d33f1ea38c9eb2395034c467ef2 run: - exec: echo "Beginning of custom commands" ## If you want to set the 'From' email address for your first registration, uncomment and change: diff --git a/discourse-prod.yml b/discourse-prod.yml index fb27835..20c01c9 100644 --- a/discourse-prod.yml +++ b/discourse-prod.yml @@ -1,3 +1,4 @@ +base_image: discourse/base:2.0.20220818-0047 templates: - "includes/moz.web.template.yml" - "includes/contribute.yml" @@ -23,16 +24,16 @@ hooks: cd: $home/plugins cmd: - mkdir -p plugins - - git clone https://github.com/discourse/discourse-akismet.git # 11ef295b5c65684f00ccf55cb4bef5656cd0ba9b - - git clone https://github.com/mozilla/discourse-mozilla-iam.git # f66123785a02a67ca10d13649cea00c772f7e40a - - git clone https://github.com/mozilla/discourse-expose-emails-in.git # e4e92b02bd150c72585eba232a27aa4bf9e7f5fb - - git clone https://github.com/mozilla/discourse-post-read-email.git # 0031da69216ba759cbf5cdda4ff4ad818e4a617f - - git clone https://github.com/discourse/discourse-solved.git # 02981fe1d9463cee4d8f64228a74da21fc38d90b - - git clone https://github.com/mozilla/discourse-sidekiq-monitor.git # 34178b637ea508d2ef103b6d48d2e0c21af155dd - - git clone https://github.com/mozilla/discourse-mozilla-letter-avatar.git # a5cc90fdafe523a21b5b54abe63d7798efe77b49 - - git clone https://github.com/mozilla/discourse-auto-email-in # ca205f63e8b8852154fddd30bf09c994070727e2 - - git clone https://github.com/mozilla/discourse-group-category-notification.git # 8be0c45e8a19c4c702a8a468e882d9968a967ee9 - - git clone https://github.com/mozilla/discourse-mozilla-gcm # 1d15d63e6dca4d33f1ea38c9eb2395034c467ef2 + - git clone https://github.com/discourse/discourse-akismet; cd discourse-akismet; git checkout 11ef295b5c65684f00ccf55cb4bef5656cd0ba9b + - git clone https://github.com/mozilla/discourse-mozilla-iam; cd discourse-mozilla-iam; git checkout f66123785a02a67ca10d13649cea00c772f7e40a + - git clone https://github.com/mozilla/discourse-expose-emails-in; cd discourse-expose-emails-in; git checkout e4e92b02bd150c72585eba232a27aa4bf9e7f5fb + - git clone https://github.com/mozilla/discourse-post-read-email; cd discourse-post-read-email; git checkout 0031da69216ba759cbf5cdda4ff4ad818e4a617f + - git clone https://github.com/discourse/discourse-solved; cd discourse-solved; git checkout 02981fe1d9463cee4d8f64228a74da21fc38d90b + - git clone https://github.com/mozilla/discourse-sidekiq-monitor; cd discourse-sidekiq-monitor; git checkout 34178b637ea508d2ef103b6d48d2e0c21af155dd + - git clone https://github.com/mozilla/discourse-mozilla-letter-avatar; cd discourse-mozilla-letter-avatar; git checkout a5cc90fdafe523a21b5b54abe63d7798efe77b49 + - git clone https://github.com/mozilla/discourse-auto-email-in; cd discourse-auto-email-in; git checkout ca205f63e8b8852154fddd30bf09c994070727e2 + - git clone https://github.com/mozilla/discourse-group-category-notification; cd discourse-group-category-notification; git checkout 8be0c45e8a19c4c702a8a468e882d9968a967ee9 + - git clone https://github.com/mozilla/discourse-mozilla-gcm; cd discourse-mozilla-gcm; git checkout 1d15d63e6dca4d33f1ea38c9eb2395034c467ef2 run: - exec: echo "Beginning of custom commands" ## If you want to set the 'From' email address for your first registration, uncomment and change: diff --git a/discourse-stage.yml b/discourse-stage.yml index 526fc0b..15e773e 100644 --- a/discourse-stage.yml +++ b/discourse-stage.yml @@ -1,3 +1,4 @@ +base_image: discourse/base:2.0.20220818-0047 templates: - "includes/moz.web.template.yml" - "includes/contribute.yml" @@ -23,16 +24,16 @@ hooks: cd: $home/plugins cmd: - mkdir -p plugins - - git clone https://github.com/discourse/discourse-akismet.git - - git clone https://github.com/mozilla/discourse-mozilla-iam.git -b development - - git clone https://github.com/mozilla/discourse-expose-emails-in.git -b development - - git clone https://github.com/mozilla/discourse-post-read-email.git -b development - - git clone https://github.com/discourse/discourse-solved.git - - git clone https://github.com/mozilla/discourse-sidekiq-monitor.git - - git clone https://github.com/mozilla/discourse-mozilla-letter-avatar.git - - git clone https://github.com/mozilla/discourse-auto-email-in -b development - - git clone https://github.com/mozilla/discourse-group-category-notification.git -b development - - git clone https://github.com/mozilla/discourse-mozilla-gcm -b development + - git clone https://github.com/discourse/discourse-akismet; cd discourse-akismet; git checkout 6abd5d252c4435ac5a507d04113b7ff306d833b7 + - git clone https://github.com/mozilla/discourse-mozilla-iam; cd discourse-mozilla-iam; git checkout f66123785a02a67ca10d13649cea00c772f7e40a + - git clone https://github.com/mozilla/discourse-expose-emails-in; cd discourse-expose-emails-in; git checkout e4e92b02bd150c72585eba232a27aa4bf9e7f5fb + - git clone https://github.com/mozilla/discourse-post-read-email; cd discourse-post-read-email; git checkout 0031da69216ba759cbf5cdda4ff4ad818e4a617f + - git clone https://github.com/discourse/discourse-solved; cd discourse-solved; git checkout 30248619e28d5f173c4dfd149d3d8ba39e3b8796 + - git clone https://github.com/mozilla/discourse-sidekiq-monitor; cd discourse-sidekiq-monitor; git checkout 34178b637ea508d2ef103b6d48d2e0c21af155dd + - git clone https://github.com/mozilla/discourse-mozilla-letter-avatar; cd discourse-mozilla-letter-avatar; git checkout a5cc90fdafe523a21b5b54abe63d7798efe77b49 + - git clone https://github.com/mozilla/discourse-auto-email-in; cd discourse-auto-email-in; git checkout ca205f63e8b8852154fddd30bf09c994070727e2 + - git clone https://github.com/mozilla/discourse-group-category-notification; cd discourse-group-category-notification; git checkout 8be0c45e8a19c4c702a8a468e882d9968a967ee9 + - git clone https://github.com/mozilla/discourse-mozilla-gcm; cd discourse-mozilla-gcm; git checkout 1d15d63e6dca4d33f1ea38c9eb2395034c467ef2 run: - exec: echo "Beginning of custom commands" ## If you want to set the 'From' email address for your first registration, uncomment and change: