From f97d13ceef29ed972701509ebe9e46dc9ee7a5a6 Mon Sep 17 00:00:00 2001 From: Grzegorz Kowalik Date: Mon, 6 Sep 2021 11:51:40 +0200 Subject: [PATCH 1/2] Add workflow for production deployment --- .github/workflows/deploy-prod.yaml | 61 ++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 .github/workflows/deploy-prod.yaml diff --git a/.github/workflows/deploy-prod.yaml b/.github/workflows/deploy-prod.yaml new file mode 100644 index 000000000..70e10c320 --- /dev/null +++ b/.github/workflows/deploy-prod.yaml @@ -0,0 +1,61 @@ +name: Deploy to production +on: + workflow_dispatch: + inputs: + service_name: + description: Name of the service + required: true + region: + description: Region to which deploy (eu or us) + required: true + git_ref: + description: Git ref (tag, branch or full commit hash) to deploy + required: true + +jobs: + build: + runs-on: ubuntu-20.04 + env: + API_URI: /graphql/ + APP_MOUNT_URI: /dashboard/ + STATIC_URL: /dashboard/static/ + SENTRY_ORG: saleor + SENTRY_PROJECT: dashboard + SENTRY_URL_PREFIX: "~/dashboard/static" + ENVIRONMENT: ${{ github.event.inputs.service_name }} + SENTRY_DSN: ${{ secrets.SENTRY_DSN }} + SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} + steps: + - uses: actions/checkout@v2 + with: + ref: ${{ github.event.inputs.chart_git_ref }} + - name: Package + timeout-minutes: 15 + run: | + npm ci + - name: build + run: | + npm run build + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_PROD_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_PROD_SECRET_ACCESS_KEY }} + aws-region: us-east-1 + - name: Deploy + run: | + REGION=${{ github.event.inputs.region }} + if [[ "$REGION" == "us" ]]; then + BUCKET=${{ secrets.AWS_PROD_US_DEPLOYMENT_BUCKET }} + CF_ID=${{ secrets.AWS_PROD_US_CF_DIST_ID }} + elif [[ "$REGION" == "eu" ]]; then + BUCKET=${{ secrets.AWS_PROD_EU_DEPLOYMENT_BUCKET }} + CF_ID=${{ secrets.AWS_PROD_EU_CF_DIST_ID }} + else + echo "Unknown region provided" + exit 1 + fi + + aws s3 sync build/dashboard s3://${BUCKET}/${ENVIRONMENT}/static/ + aws s3 cp build/dashboard/index.html s3://${BUCKET}/${ENVIRONMENT}/ + aws cloudfront create-invalidation --distribution-id ${CF_ID} --paths "/dashboard*" From e7720da33ba6bd778c434e2a66e196f9669805ed Mon Sep 17 00:00:00 2001 From: Grzegorz Kowalik Date: Tue, 7 Sep 2021 12:55:40 +0200 Subject: [PATCH 2/2] Add manual trigger for staging deployment workflow --- .github/workflows/deploy-staging.yaml | 45 +++++++++++++++++---------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/.github/workflows/deploy-staging.yaml b/.github/workflows/deploy-staging.yaml index 7efc99b97..0c530323c 100644 --- a/.github/workflows/deploy-staging.yaml +++ b/.github/workflows/deploy-staging.yaml @@ -4,6 +4,14 @@ on: branches: - master - ci/staging/** + workflow_dispatch: + inputs: + git_ref: + description: Git ref (tag, branch or commit hash) with helm chart to deploy + required: true + service_name: + description: Name of the service + required: true jobs: build: runs-on: ubuntu-20.04 @@ -14,28 +22,33 @@ jobs: SENTRY_ORG: saleor SENTRY_PROJECT: dashboard SENTRY_URL_PREFIX: "~/dashboard/static" - ENVIRONMENT: master-staging SENTRY_DSN: ${{ secrets.SENTRY_DSN }} SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} steps: + - name: Set env variables + run: | + set -x + + GIT_REF_INPUT=${{ github.event.inputs.git_ref }} + GIT_REF="${GIT_REF_INPUT:=master}" + + SERVICE_NAME_INPUT=${{ github.event.inputs.service_name }} + SERVICE_NAME="${SERVICE_NAME_INPUT:=saleor-master-staging}" + + echo "export GIT_REF=$GIT_REF" >> $GITHUB_ENV + # ENVIRONMENT variable is provided to sentry at build time + echo "export ENVIRONMENT=$SERVICE_NAME" >> $GITHUB_ENV + - uses: actions/checkout@v2 + with: + ref: ${{ env.GIT_REF }} - name: Package + timeout-minutes: 15 run: | npm ci + - name: Build + run: | npm run build - - uses: actions/upload-artifact@v2 - with: - name: build - path: build - deploy: - needs: - - build - runs-on: ubuntu-20.04 - steps: - - uses: actions/download-artifact@v2 - with: - name: build - path: build - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v1 with: @@ -44,6 +57,6 @@ jobs: aws-region: us-east-1 - name: Deploy run: | - aws s3 sync build/dashboard s3://${{ secrets.AWS_STAGING_DEPLOYMENT_BUCKET }}/saleor-master-staging/static/ - aws s3 cp build/dashboard/index.html s3://${{ secrets.AWS_STAGING_DEPLOYMENT_BUCKET }}/saleor-master-staging/ + aws s3 sync build/dashboard s3://${{ secrets.AWS_STAGING_DEPLOYMENT_BUCKET }}/${ENVIRONMENT}/static/ + aws s3 cp build/dashboard/index.html s3://${{ secrets.AWS_STAGING_DEPLOYMENT_BUCKET }}/${ENVIRONMENT}/ aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_STAGING_CF_DIST_ID }} --paths "/dashboard*"