-
Notifications
You must be signed in to change notification settings - Fork 58
114 lines (99 loc) · 3.33 KB
/
docker-build-and-publish.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
name: Docker Build and Push
on:
pull_request:
branches: [main]
# workflow_run:
# workflows: ["Release Build"]
# types: [completed]
env:
REGISTRY_IMAGE_API: fynnfluegge/rocketnotes-api
REGISTRY_IMAGE_WEBAPP: fynnfluegge/rocketnotes-webapp
AWS_REGION: ${{ vars.AWS_REGION }}
DOMAIN_NAME: ${{ vars.DOMAIN_NAME }}
API_URL: ${{ vars.API_URL }}
COGNITO_USER_POOL_ID: ${{ vars.COGNITO_USER_POOL_ID }}
COGNITO_APP_CLIENT_ID: ${{ vars.COGNITO_APP_CLIENT_ID }}
REDIRECT_SIGN_IN: ${{ vars.REDIRECT_SIGN_IN }}
REDIRECT_SIGN_OUT: ${{ vars.REDIRECT_SIGN_OUT }}
AUTH_GUARD_REDIRECT: ${{ vars.AUTH_GUARD_REDIRECT }}
jobs:
build-and-push:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Cache node modules
id: cache-npm
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Build webapp
run: |
cd webapp
npm ci
npm run build
env:
AWS_REGION: ${{ vars.AWS_REGION }}
DOMAIN_NAME: ${{ vars.DOMAIN_NAME }}
API_URL: ${{ vars.API_URL }}
COGNITO_USER_POOL_ID: ${{ vars.COGNITO_USER_POOL_ID }}
COGNITO_APP_CLIENT_ID: ${{ vars.COGNITO_APP_CLIENT_ID }}
REDIRECT_SIGN_IN: ${{ vars.REDIRECT_SIGN_IN }}
REDIRECT_SIGN_OUT: ${{ vars.REDIRECT_SIGN_OUT }}
AUTH_GUARD_REDIRECT: ${{ vars.AUTH_GUARD_REDIRECT }}
# - uses: dawidd6/action-download-artifact@v2
# with:
# name: webapp-build
# path: webapp/build
# run_id: ${{ github.event.workflow_run.id }}
- uses: actions/setup-python@v5
with:
python-version: "3.9"
- uses: aws-actions/setup-sam@v2
with:
use-installer: true
token: ${{ secrets.GITHUB_TOKEN }}
- run: sam build
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract release tag
id: get_tag
run: echo "RELEASE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Build and push Docker image api
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.sam
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ env.REGISTRY_IMAGE_API }}:latest
- name: Build and push Docker image webapp
uses: docker/build-push-action@v5
with:
context: webapp/.
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ env.REGISTRY_IMAGE_WEBAPP }}:latest