-
Notifications
You must be signed in to change notification settings - Fork 0
183 lines (178 loc) · 6.69 KB
/
workflow.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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
name: Tosiscan build and deploy workflow
on:
push:
branches:
- main
- test
paths:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Dump Contexts
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
RUNNER_CONTEXT: ${{ toJSON(runner) }}
run: |
echo "$GITHUB_CONTEXT"
echo "$RUNNER_CONTEXT"
# git context is the default for actions but this will fail for docker in
# a monorepo with multiple (docker) build contexts. As such, we must
# checkout...
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx--${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx--
- name: Build
uses: docker/build-push-action@v3
env:
REACT_APP_DATACHAIN_BASE_URL: "https://tosiscan-testnet-one.zippie.com"
with:
context: .
file: Dockerfile
load: true # persist the image so later step(s) can call it
tags: ${{github.event.repository.name}}:${{github.sha}}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- # Currently there is no way to cleanly export a docker image between
# jobs so instead we package a tarball so that subsequent jobs can
# download it.
name: Package
run: |
rm -rf /tmp/${{github.sha}}
mkdir /tmp/${{github.sha}}
docker create --name=${{github.sha}} \
${{github.event.repository.name}}:${{github.sha}}
docker cp ${{github.sha}}:/app//build /tmp/${{github.sha}}/
echo ${{github.sha}} > /tmp/${{github.sha}}/build/version.txt
cd /tmp && tar cfJ /tmp/${{github.sha}}.txz ${{github.sha}}
- name: Intermediate Artifact Upload
uses: actions/upload-artifact@v3
with:
name: ${{github.sha}}
path: /tmp/${{github.sha}}.txz
retention-days: 15
- # 'Temporary' cleanup fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
name: Docker Cache Management
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
if: always()
env:
SLACK_WEBHOOK: ${{secrets.SLACK_WEBHOOK_CIBOT}}
SLACK_CHANNEL: cibot
SLACK_COLOR: ${{job.status}}
SLACK_USERNAME: Zippie Actions
SLACK_TITLE: '${{github.repository}}: ${{github.job}}: ${{github.ref}} event triggered workflow run ${{github.run_number}}'
SLACK_MESSAGE: 'Build ${{job.status}}: https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}'
SLACK_FOOTER: commit ${{github.sha}}
SLACK_ICON_EMOJI: ':beers:'
MSG_MINIMAL: true
deploydev:
if: github.ref == 'refs/heads/main'
env:
BUCKET: z-dev-tosiscan
runs-on: ubuntu-latest
needs: build
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: us-east-1
aws-access-key-id: ${{ secrets.DEV_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.DEV_AWS_SECRET_ACCESS_KEY }}
- name: Intermediate Artifact Download
uses: actions/download-artifact@v2
with:
name: ${{github.sha}}
path: /tmp/
- name: s3 sync
run: |
echo "Bucket is set to ${BUCKET}"
cd /tmp
tar xfvJ /tmp/${{github.sha}}.txz
cd /tmp/${{github.sha}}/build
aws s3 sync --delete . s3://${BUCKET}/public/
# NOTE! awscliv2 syntax
# NOTE! metadata permissions differ between environments
aws s3 cp s3://${BUCKET}/public s3://${BUCKET}/public \
--exclude '*' \
--include '*.html' \
--include '*.css' \
--include '*.js' \
--include '*.json' \
--cache-control 'no-store, must-revalidate' \
--copy-props 'metadata-directive' \
--recursive
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
if: always()
env:
SLACK_WEBHOOK: ${{secrets.SLACK_WEBHOOK_CIBOT}}
SLACK_CHANNEL: cibot
SLACK_COLOR: ${{job.status}}
SLACK_USERNAME: Zippie Actions
SLACK_TITLE: '${{github.repository}}: ${{github.job}}: ${{github.job.status}}'
SLACK_MESSAGE: 'https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}'
SLACK_FOOTER: commit ${{github.sha}}
SLACK_ICON_EMOJI: ':beers:'
MSG_MINIMAL: true
deploytest:
if: github.ref == 'refs/heads/test'
env:
BUCKET: z-test-tosiscan
runs-on: ubuntu-latest
needs: build
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: us-east-1
aws-access-key-id: ${{ secrets.TEST_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.TEST_AWS_SECRET_ACCESS_KEY }}
- name: Intermediate Artifact Download
uses: actions/download-artifact@v2
with:
name: ${{github.sha}}
path: /tmp/
- name: s3 sync
run: |
cd /tmp &&
tar xfJ /tmp/${{github.sha}}.txz &&
cd /tmp/${{github.sha}}/build &&
aws s3 sync --delete . s3://${BUCKET}/public/
# NOTE! awscliv2 syntax
# NOTE! metadata permissions differ between environments
aws s3 cp s3://${BUCKET}/public s3://${BUCKET}/public \
--exclude '*' \
--include '*.html' \
--include '*.css' \
--include '*.js' \
--include '*.json' \
--cache-control 'max-age=300, must-revalidate' \
--copy-props 'metadata-directive' \
--recursive
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
if: always()
env:
SLACK_WEBHOOK: ${{secrets.SLACK_WEBHOOK_CIBOT}}
SLACK_CHANNEL: cibot
SLACK_COLOR: ${{job.status}}
SLACK_USERNAME: Zippie Actions
SLACK_TITLE: '${{github.repository}}: ${{github.job}}: ${{github.job.status}}'
SLACK_MESSAGE: 'https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}'
SLACK_FOOTER: commit ${{github.sha}}
SLACK_ICON_EMOJI: ':beers:'
MSG_MINIMAL: true