This repository has been archived by the owner on Jun 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
150 lines (140 loc) · 7.49 KB
/
deploy-vue-storefront-cloud.yml
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
name: Deploy to Vue Storefront Cloud
on:
push:
branches:
- main
jobs:
configure-deployment:
runs-on: ubuntu-latest
outputs:
env-info-file: ${{ steps.resolve-env-filename.outputs.env-info-file }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Determine environment-specific variables
shell: bash
id: resolve-env-filename
run: |
REF=${{ github.ref }}
if [ $REF = 'refs/heads/main' ]; then
ENVINFO_FILE=production
else
echo 'unrecognized branch name'
exit 1
fi
echo "env-info-file=$ENVINFO_FILE" >> $GITHUB_OUTPUT
echo "Selected environment: $ENVINFO_FILE"
build-storefront:
runs-on: ubuntu-latest
needs: configure-deployment
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup deployment environments variables
shell: bash
run: |
cat .github/workflows/public_env_info/${{ needs.configure-deployment.outputs.env-info-file }} >> $GITHUB_ENV
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: "16.x"
- name: Build and publish docker image
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: ${{ secrets.PROJECT_NAME }}-storefrontcloud-io/vue-storefront:${{ github.sha }}
registry: ${{ secrets.DOCKER_REGISTRY_URL || 'registry.vuestorefront.cloud' }}
username: ${{ secrets.CLOUD_USERNAME }}
password: ${{ secrets.CLOUD_PASSWORD }}
dockerfile: .vuestorefrontcloud/docker/storefront/Dockerfile
buildoptions: "--compress"
buildargs: NPM_EMAIL,NPM_PASS,NPM_USER,NPM_REGISTRY,VSF_NUXT_APP_ENV,VSF_NUXT_APP_PORT,VSF_NUXT_APP_HOST,VSF_STORE_URL,API_BASE_URL,API_SSR_BASE_URL,VSF_MAGENTO_BASE_URL,VSF_MAGENTO_GRAPHQL_URL,VSF_MAGENTO_EXTERNAL_CHECKOUT_ENABLED,VSF_MAGENTO_EXTERNAL_CHECKOUT_URL,VSF_MAGENTO_EXTERNAL_CHECKOUT_SYNC_PATH,NUXT_IMAGE_PROVIDER,NUXT_IMAGE_PROVIDER_BASE_URL,NUXT_IMAGE_PROVIDER_DOMAIN,VSF_REDIS_ENABLED,VSF_REDIS_HOST,VSF_REDIS_PORT,VSF_REDIS_KEY_PREFIX,VSF_REDIS_CACHE_INVALIDATE_URL,VSF_RECAPTCHA_ENABLED,VSF_RECAPTCHA_SITE_KEY,VSF_RECAPTCHA_SECRET_KEY,VSF_RECAPTCHA_HIDE_BADGE,VSF_RECAPTCHA_SIZE,VSF_RECAPTCHA_MIN_SCORE,VSF_RECAPTCHA_VERSION,VSF_COOKIE_HTTP_ONLY,VSF_COOKIE_SECURE,VSF_COOKIE_SAME_SITE,VSF_COOKIE_PATH
env:
NPM_EMAIL: ${{ secrets.NPM_EMAIL }}
NPM_PASS: ${{ secrets.NPM_PASS }}
NPM_USER: ${{ secrets.NPM_USER }}
NPM_REGISTRY: "https://registrynpm.storefrontcloud.io"
build-middleware:
runs-on: ubuntu-latest
needs: configure-deployment
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup deployment environments variables
shell: bash
run: |
cat .github/workflows/public_env_info/${{ needs.configure-deployment.outputs.env-info-file }} >> $GITHUB_ENV
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: "16.x"
- name: Build and publish docker image
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: ${{ secrets.PROJECT_NAME }}-storefrontcloud-io/vue-storefront-middleware:${{ github.sha }}
registry: ${{ secrets.DOCKER_REGISTRY_URL || 'registry.vuestorefront.cloud' }}
username: ${{ secrets.CLOUD_USERNAME }}
password: ${{ secrets.CLOUD_PASSWORD }}
dockerfile: .vuestorefrontcloud/docker/middleware/Dockerfile
buildoptions: "--compress"
buildargs: NPM_EMAIL,NPM_PASS,NPM_USER,NPM_REGISTRY,VSF_NUXT_APP_ENV,VSF_NUXT_APP_PORT,VSF_NUXT_APP_HOST,VSF_STORE_URL,API_BASE_URL,API_SSR_BASE_URL,VSF_MAGENTO_BASE_URL,VSF_MAGENTO_GRAPHQL_URL,VSF_MAGENTO_EXTERNAL_CHECKOUT_ENABLED,VSF_MAGENTO_EXTERNAL_CHECKOUT_URL,VSF_MAGENTO_EXTERNAL_CHECKOUT_SYNC_PATH,NUXT_IMAGE_PROVIDER,NUXT_IMAGE_PROVIDER_BASE_URL,NUXT_IMAGE_PROVIDER_DOMAIN,VSF_REDIS_ENABLED,VSF_REDIS_HOST,VSF_REDIS_PORT,VSF_REDIS_KEY_PREFIX,VSF_REDIS_CACHE_INVALIDATE_URL,VSF_RECAPTCHA_ENABLED,VSF_RECAPTCHA_SITE_KEY,VSF_RECAPTCHA_SECRET_KEY,VSF_RECAPTCHA_HIDE_BADGE,VSF_RECAPTCHA_SIZE,VSF_RECAPTCHA_MIN_SCORE,VSF_RECAPTCHA_VERSION,VSF_COOKIE_HTTP_ONLY,VSF_COOKIE_SECURE,VSF_COOKIE_SAME_SITE,VSF_COOKIE_PATH
env:
NPM_EMAIL: ${{ secrets.NPM_EMAIL }}
NPM_PASS: ${{ secrets.NPM_PASS }}
NPM_USER: ${{ secrets.NPM_USER }}
NPM_REGISTRY: "https://registrynpm.storefrontcloud.io"
deploy:
runs-on: ubuntu-latest
permissions:
deployments: write
needs: [configure-deployment, build-storefront, build-middleware]
steps:
- uses: chrnorm/deployment-action@v2
name: Create GitHub deployment
id: deployment
with:
token: "${{ github.token }}"
environment-url: https://${{ secrets.PROJECT_NAME }}.${{ secrets.CLOUD_REGION }}.gcp.storefrontcloud.io
environment: production
initial-status: in_progress
- name: Deploy on ${{ secrets.PROJECT_NAME }}.${{ secrets.CLOUD_REGION }}.gcp.storefrontcloud.io
run: |
curl --location --request PATCH '${{ secrets.PLATFORM_API_URL || 'https://api.platform.vuestorefront.io' }}/cloud/instances/${{ secrets.PROJECT_NAME }}-${{ secrets.CLOUD_REGION }}-gcp-storefrontcloud-io/deploy' --header 'Content-Type: application/json' --data-raw '{ "cloudUserId": "${{ secrets.CLOUD_USERNAME }}", "cloudUserPassword": "${{ secrets.CLOUD_PASSWORD }}", "dockerImageHash": "${{ github.sha }}"}'
- name: Deploy middleware on ${{ secrets.PROJECT_NAME }}.${{ secrets.CLOUD_REGION }}.gcp.storefrontcloud.io/api/
run: |
if curl -f -s -H 'X-User-Id: ${{ secrets.CLOUD_USERNAME }}' -H 'X-Api-Key: ${{ secrets.CLOUD_PASSWORD }}' -H 'Content-Type: application/json' -X PATCH -d '{
"front_version":"${{ github.sha }}",
"additional_apps": {
"apps":[{
"name":"middleware",
"tag":"${{ github.sha }}",
"image":"${{ secrets.DOCKER_REGISTRY_URL || 'registry.vuestorefront.cloud' }}/${{ secrets.PROJECT_NAME }}-storefrontcloud-io/vue-storefront-middleware",
"path":"/api/",
"port":"8181",
"has_base_path":false
}],
"enabled": true
}
}' ${{ secrets.CLOUD_API_BASE_URL || 'https://farmer.vuestorefront.cloud' }}/instance/${{ secrets.PROJECT_NAME }}-${{ secrets.CLOUD_REGION }}-gcp-storefrontcloud-io; then
echo "Instance updated"
else
echo "Something went wrong during the update process..."
exit 1
fi
- name: Update deployment status (success)
if: success()
uses: chrnorm/deployment-status@v2
with:
token: "${{ github.token }}"
environment-url: https://${{ secrets.PROJECT_NAME }}.${{ secrets.CLOUD_REGION }}.gcp.storefrontcloud.io
state: "success"
description: Congratulations! The deploy is done.
deployment-id: ${{ steps.deployment.outputs.deployment_id }}
- name: Update deployment status (failure)
if: failure()
uses: chrnorm/deployment-status@v2
with:
token: "${{ github.token }}"
environment-url: https://${{ secrets.PROJECT_NAME }}.${{ secrets.CLOUD_REGION }}.gcp.storefrontcloud.io
state: "failure"
description: Unfortunately, the instance hasn't been updated.
deployment-id: ${{ steps.deployment.outputs.deployment_id }}