From 97f8356934678d37ad3d982220693da263b8aa2d Mon Sep 17 00:00:00 2001 From: Josh Worden Date: Fri, 6 Dec 2024 15:32:53 -0600 Subject: [PATCH 1/2] commit generated gha workflows --- .github/workflows/deploy-production.yml | 79 +++++++++++------------ .github/workflows/deploy-staging.yml | 85 +++++++++++++++++++++++++ .github/workflows/node-ci.yml | 15 ++--- 3 files changed, 127 insertions(+), 52 deletions(-) create mode 100644 .github/workflows/deploy-staging.yml diff --git a/.github/workflows/deploy-production.yml b/.github/workflows/deploy-production.yml index c0b8459..1fbe5a9 100644 --- a/.github/workflows/deploy-production.yml +++ b/.github/workflows/deploy-production.yml @@ -2,11 +2,8 @@ name: Deploy newsletters (production) on: push: - tags: [ 'v[0-9]+.[0-9]+.[0-9]+' ] - -env: - ECR_REGISTRY: 598984531759.dkr.ecr.us-east-2.amazonaws.com - IMG_PREFIX: science-medicine-group + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' jobs: version: @@ -43,50 +40,46 @@ jobs: with: slack-thread: ${{ needs.notify-start.outputs.slack-thread }} - ###################### - # Add tenants here! # - ###################### + ######################### + # Add newsletters here! # + ######################### build-newsletters: needs: [version] - runs-on: ubuntu-latest + uses: parameter1/actions/.github/workflows/newsletter-build-push-test.yml@main strategy: matrix: - tenant: - - all - steps: - - uses: actions/checkout@v4 - - name: Log in to ECR - uses: docker/login-action@v2 - with: - registry: ${{ env.ECR_REGISTRY }} - username: ${{ secrets.AWS_ACCESS_KEY_ID }} - password: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - - name: Build docker image - uses: docker/build-push-action@v3 - with: - push: true - build-args: | - TENANT=${{ matrix.tenant }} - tags: ${{ env.ECR_REGISTRY }}/base-cms-newsletters:${{ env.IMG_PREFIX }}-${{ matrix.tenant }}-${{ needs.version.outputs.version }} + ##################################################### + #v# Make sure this matches the newsletter matrix! #v# + ##################################################### + newsletter: + - { stack: virgon, account: science-medicine-group, tenant: all, rancher_label: science-medicine-group-all } + ##################################################### + #^# Make sure this matches the newsletter matrix! #^# + ##################################################### + with: + ecr_registry: ${{ vars.AWS_ECR_REGISTRY }} + docker_image: ${{ vars.AWS_ECR_REGISTRY }}/mindful-web/newsletters:${{ matrix.newsletter.account }}-${{ matrix.newsletter.tenant }}-${{ needs.version.outputs.version }} + tenant: ${{ matrix.newsletter.tenant }} + push: true + secrets: inherit deploy-newsletters: - needs: [version, build-newsletters ] - runs-on: ubuntu-latest + needs: [version, build-newsletters] + uses: parameter1/actions/.github/workflows/newsletter-deploy-production.yml@main strategy: matrix: - namespace: - - virgon-newsletters - tenant: - - all - steps: - - name: Deploy to Kubernetes - run: | - npx @parameter1/rancher2cli dl \ - --wait --namespace ${{ matrix.namespace }} \ - basecms-newsletter ${{ env.IMG_PREFIX }}-${{ matrix.tenant }} \ - ${{ env.ECR_REGISTRY }}/base-cms-newsletters:${{ env.IMG_PREFIX }}-${{ matrix.tenant }}-${{ needs.version.outputs.version }} - env: - RANCHER_CLUSTERID: ${{ secrets.RANCHER_CLUSTERID_BASECMS }} - RANCHER_TOKEN: ${{ secrets.RANCHER_TOKEN }} - RANCHER_URL: ${{ secrets.RANCHER_URL }} + ##################################################### + #v# Make sure this matches the newsletter matrix! #v# + ##################################################### + newsletter: + - { stack: virgon, account: science-medicine-group, tenant: all, rancher_label: science-medicine-group-all } + ##################################################### + #^# Make sure this matches the newsletter matrix! #^# + ##################################################### + with: + docker_image: ${{ vars.AWS_ECR_REGISTRY }}/mindful-web/newsletters:${{ matrix.newsletter.account }}-${{ matrix.newsletter.tenant }}-${{ needs.version.outputs.version }} + infra_stack: ${{ matrix.newsletter.stack }} + rancher_label_key: mindful-web-newsletter + rancher_label_val: ${{ matrix.newsletter.rancher_label }} + secrets: inherit diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml new file mode 100644 index 0000000..b12329e --- /dev/null +++ b/.github/workflows/deploy-staging.yml @@ -0,0 +1,85 @@ +name: Deploy newsletters (staging) + +on: + push: + branches: + - staging + +jobs: + version: + runs-on: ubuntu-latest + steps: + - id: tag_version + run: | + REF=$(echo $GITHUB_REF | cut -d / -f 3) + [[ "$GITHUB_REF" =~ ^refs/tags.*$ ]] && VERSION="$REF" || VERSION="${REF}-${GITHUB_SHA::7}" + echo "version=$VERSION" >> $GITHUB_OUTPUT + outputs: + version: ${{ steps.tag_version.outputs.version }} + + notify-start: + needs: [version] + uses: parameter1/actions/.github/workflows/notify-start.yml@main + secrets: inherit + with: + version: ${{ needs.version.outputs.version }} + + post-deploy-failure: + if: failure() + needs: [notify-start, build-newsletters, deploy-newsletters] + uses: parameter1/actions/.github/workflows/notify-fail.yml@main + secrets: inherit + with: + slack-thread: ${{ needs.notify-start.outputs.slack-thread }} + + post-deploy-complete: + if: success() + needs: [notify-start, build-newsletters, deploy-newsletters] + uses: parameter1/actions/.github/workflows/notify-complete.yml@main + secrets: inherit + with: + slack-thread: ${{ needs.notify-start.outputs.slack-thread }} + + ######################### + # Add newsletters here! # + ######################### + + build-newsletters: + needs: [version] + uses: parameter1/actions/.github/workflows/newsletter-build-push-test.yml@main + strategy: + matrix: + ##################################################### + #v# Make sure this matches the newsletter matrix! #v# + ##################################################### + newsletter: + - { stack: virgon, account: science-medicine-group, tenant: all, rancher_label: science-medicine-group-all } + ##################################################### + #^# Make sure this matches the newsletter matrix! #^# + ##################################################### + with: + ecr_registry: ${{ vars.AWS_ECR_REGISTRY }} + docker_image: ${{ vars.AWS_ECR_REGISTRY }}/mindful-web/newsletters-staging:${{ matrix.newsletter.account }}-${{ matrix.newsletter.tenant }}-${{ needs.version.outputs.version }} + tenant: ${{ matrix.newsletter.tenant }} + push: true + secrets: inherit + + deploy-newsletters: + needs: [version, build-newsletters] + uses: parameter1/actions/.github/workflows/newsletter-deploy-staging.yml@main + strategy: + matrix: + ##################################################### + #v# Make sure this matches the newsletter matrix! #v# + ##################################################### + newsletter: + - { stack: virgon, account: science-medicine-group, tenant: all, rancher_label: science-medicine-group-all } + ##################################################### + #^# Make sure this matches the newsletter matrix! #^# + ##################################################### + with: + docker_image: ${{ vars.AWS_ECR_REGISTRY }}/mindful-web/newsletters-staging:${{ matrix.newsletter.account }}-${{ matrix.newsletter.tenant }}-${{ needs.version.outputs.version }} + infra_stack: ${{ matrix.newsletter.stack }} + rancher_label_key: mindful-web-newsletter + rancher_label_val: ${{ matrix.newsletter.rancher_label }} + secrets: inherit diff --git a/.github/workflows/node-ci.yml b/.github/workflows/node-ci.yml index 4d9100b..b215c7d 100644 --- a/.github/workflows/node-ci.yml +++ b/.github/workflows/node-ci.yml @@ -1,26 +1,23 @@ -# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions - name: Node.js CI on: push: - branches: [ main ] + branches: ["*"] pull_request: - branches: [ main ] + branches: ["*"] jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v4 with: node-version: 14.21 - - uses: actions/cache@v2 + - uses: actions/cache@v4 id: yarn-cache with: path: '**/node_modules' @@ -28,6 +25,6 @@ jobs: - name: Install dependencies if: steps.yarn-cache.outputs.cache-hit != 'true' - run: yarn install --pure-lockfile + run: yarn install --frozen-lockfile - run: yarn test From dff8656a37652d71e5eb2ba8291f245d00e751ca Mon Sep 17 00:00:00 2001 From: Josh Worden Date: Fri, 6 Dec 2024 15:32:54 -0600 Subject: [PATCH 2/2] Add mindful-web-newsletter command/config --- package.json | 1 + tenants/all/package.json | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/package.json b/package.json index ec1cb04..bf642dc 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "scripts": { "build": "lerna run build", "compile": "lerna run compile", + "generate-gha-workflows": "mindful-web-newsletter generate-gha-workflows", "lint": "lerna run lint", "lint:fix": "lerna run lint:fix", "test": "lerna run test" diff --git a/tenants/all/package.json b/tenants/all/package.json index 6775fbc..602fb14 100644 --- a/tenants/all/package.json +++ b/tenants/all/package.json @@ -5,6 +5,12 @@ "repository": "https://github.com/parameter1/science-medicine-group-newsletters/tree/main/tenants/all", "license": "MIT", "private": true, + "newsletter": { + "account": "science-medicine-group", + "tenant": "all", + "stack": "virgon", + "deploy": true + }, "scripts": { "build": "yarn compile", "dev": "basecms-newsletters dev --compile-dir ../../packages --watch-dir ../../packages",