-
Notifications
You must be signed in to change notification settings - Fork 1.1k
111 lines (101 loc) · 4.34 KB
/
deploy-cloud.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
name: Deploy to cloud
on:
repository_dispatch:
types: cloud-deployment
jobs:
build:
runs-on: ubuntu-20.04
env:
## backward compatibility for older versions
APPS_MARKETPLACE_API_URI: "https://apps.saleor.io/api/v2/saleor-apps"
## backward compatibility for older versions
API_URI: /graphql/
API_URL: /graphql/
APP_MOUNT_URI: /dashboard/
STATIC_URL: /dashboard/static/
SENTRY_ORG: saleor
SENTRY_PROJECT: dashboard
SENTRY_URL_PREFIX: "~/dashboard/static"
ENVIRONMENT: ${{ github.event.client_payload.deployment_name }}
REGION: ${{ github.event.client_payload.region }}
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
APPS_MARKETPLACE_API_URL: "https://apps.saleor.io/api/v2/saleor-apps"
IS_CLOUD_INSTANCE: true
POSTHOG_KEY: ${{ secrets.POSTHOG_KEY }}
POSTHOG_HOST: ${{ secrets.POSTHOG_HOST }}
ONBOARDING_USER_JOINED_DATE_THRESHOLD: ${{ vars.CLOUD_ONBOARDING_USER_JOINED_DATE_THRESHOLD }}
steps:
- name: Check region
if: ${{ !contains(fromJSON('["eu", "us"]'), env.REGION) }}
run: echo 'Unknown region provided' >&2; exit 1
- uses: actions/checkout@v2
with:
ref: ${{ github.event.client_payload.ref }}
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: ".nvmrc"
- name: Set sentry release
run: |
HASH=$(git rev-parse --short HEAD)
CURRENT_VERSION=$(jq -r .version package.json)
RELEASE="${CURRENT_VERSION}-${HASH}"
echo "SENTRY_RELEASE=${RELEASE}" >> $GITHUB_ENV
- name: Package
timeout-minutes: 15
run: |
npm ci
- name: Build
run: |
npm run build
- name: Configure AWS Credentials
if: env.REGION == 'eu'
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_CLOUD_EU_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_CLOUD_EU_SECRET_ACCESS_KEY }}
aws-region: eu-west-1
- name: Configure AWS Credentials
if: env.REGION == 'us'
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_CLOUD_US_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_CLOUD_US_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Deploy
if: env.REGION == 'eu'
run: |
aws s3 sync build/dashboard "s3://${DEPLOYMENT_BUCKET}/${ENVIRONMENT}/static/"
aws s3 cp build/dashboard/index.html "s3://${DEPLOYMENT_BUCKET}/${ENVIRONMENT}/"
IFS=',' read -ra DISTRIBUTIONS_ARRAY <<< "${CDN_DISTRIBUTIONS}"
for DISTRIBUTION in "${DISTRIBUTIONS_ARRAY[@]}"; do
echo "::add-mask::$DISTRIBUTION"
for i in {1..3}; do aws cloudfront create-invalidation --distribution-id "$DISTRIBUTION" --paths "/dashboard*" && break || sleep 5; done
done
env:
DEPLOYMENT_BUCKET: ${{ secrets.AWS_CLOUD_EU_DEPLOYMENT_BUCKET }}
CDN_DISTRIBUTIONS: ${{ secrets.AWS_CLOUD_EU_CDN_DISTRIBUTIONS }}
- name: Deploy
if: env.REGION == 'us'
run: |
aws s3 sync build/dashboard "s3://${DEPLOYMENT_BUCKET}/${ENVIRONMENT}/static/"
aws s3 cp build/dashboard/index.html "s3://${DEPLOYMENT_BUCKET}/${ENVIRONMENT}/"
IFS=',' read -ra DISTRIBUTIONS_ARRAY <<< "${CDN_DISTRIBUTIONS}"
for DISTRIBUTION in "${DISTRIBUTIONS_ARRAY[@]}"; do
echo "::add-mask::$DISTRIBUTION"
for i in {1..3}; do aws cloudfront create-invalidation --distribution-id "$DISTRIBUTION" --paths "/dashboard*" && break || sleep 5; done
done
env:
DEPLOYMENT_BUCKET: ${{ secrets.AWS_CLOUD_US_DEPLOYMENT_BUCKET }}
CDN_DISTRIBUTIONS: ${{ secrets.AWS_CLOUD_US_CDN_DISTRIBUTIONS }}
- name: Notify Slack
if: ${{ always() }}
env:
JOB_DEPLOYMENT_KIND: production
JOB_STATUS: ${{ job.status }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_CLOUD_DEPLOYMENTS_WEBHOOK_URL }}
SLACK_MENTION_GROUP_ID: ${{ secrets.SLACK_DASHBOARD_GROUP_ID }}
JOB_TITLE: "Dashboard deployment to ${{ env.ENVIRONMENT }}"
run: |
python3 ./.github/workflows/notify/notify-slack.py