Merge pull request #1359 from mirumee/feature/production-deployment-workflow

Add workflow for production deployment
This commit is contained in:
Cezary Miącz 2021-09-07 15:25:16 +02:00 committed by GitHub
commit 97b4333c73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 90 additions and 16 deletions

61
.github/workflows/deploy-prod.yaml vendored Normal file
View file

@ -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*"

View file

@ -4,6 +4,14 @@ on:
branches: branches:
- master - master
- ci/staging/** - 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: jobs:
build: build:
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
@ -14,28 +22,33 @@ jobs:
SENTRY_ORG: saleor SENTRY_ORG: saleor
SENTRY_PROJECT: dashboard SENTRY_PROJECT: dashboard
SENTRY_URL_PREFIX: "~/dashboard/static" SENTRY_URL_PREFIX: "~/dashboard/static"
ENVIRONMENT: master-staging
SENTRY_DSN: ${{ secrets.SENTRY_DSN }} SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
steps: 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 - uses: actions/checkout@v2
with:
ref: ${{ env.GIT_REF }}
- name: Package - name: Package
timeout-minutes: 15
run: | run: |
npm ci npm ci
- name: Build
run: |
npm run build 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 - name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1 uses: aws-actions/configure-aws-credentials@v1
with: with:
@ -44,6 +57,6 @@ jobs:
aws-region: us-east-1 aws-region: us-east-1
- name: Deploy - name: Deploy
run: | run: |
aws s3 sync build/dashboard s3://${{ secrets.AWS_STAGING_DEPLOYMENT_BUCKET }}/saleor-master-staging/static/ 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 }}/saleor-master-staging/ 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*" aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_STAGING_CF_DIST_ID }} --paths "/dashboard*"