-
Notifications
You must be signed in to change notification settings - Fork 2
143 lines (131 loc) 路 4.63 KB
/
infrastructure.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
name: Infrastructure
on:
pull_request:
push:
branches:
- main
workflow_dispatch:
inputs:
commit_sha:
description: "SHA to deploy"
required: true
type: string
concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: false
# TODO: Skip if no changes in directory
jobs:
lint_docker:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- name: Run linter
uses: jbergstroem/hadolint-gh-action@83e551589b57fb5bc5ad415fbcde93da0d2641a1
with:
dockerfile: "**/*.Dockerfile"
lint_shell:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- name: Install dependencies
run: |
sudo apt install shellcheck
- name: Run shellcheck
run: ./s/shellcheck
build_api_container:
runs-on: ubuntu-latest
if: ${{ github.event_name != 'workflow_dispatch' }}
steps:
- uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: "{{defaultContext}}:backend"
push: true
file: "django.Dockerfile"
tags: recipeyak/django:${{ github.event.pull_request.head.sha || github.sha }}
cache-from: type=gha,scope=django
cache-to: type=gha,scope=django,mode=max
build-args: |
GIT_SHA=${{ github.event.pull_request.head.sha || github.sha }}
build_ui_container:
runs-on: ubuntu-latest
if: ${{ github.event_name != 'workflow_dispatch' }}
steps:
- uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: actions/setup-node@v3
with:
node-version-file: "frontend/package.json"
cache-dependency-path: "frontend/yarn.lock"
cache: "yarn"
- name: Install dependencies
working-directory: "frontend"
run: yarn install --frozen-lockfile
- name: Build
env:
FRONTEND_GIT_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
working-directory: "frontend"
run: |
# TODO: could get fancier and determine if there have been any backwards incompatible changes
export FRONTEND_API_GIT_TREE_SHA=$(shasum --algorithm 256 ../backend/api-schema.json)
s/build
- name: Build and push
working-directory: "./frontend"
run: |
git_sha=${{ github.event.pull_request.head.sha || github.sha }}
docker buildx build --push -f react.Dockerfile \
--tag recipeyak/react:$git_sha .
echo "Pushed \`recipeyak/react:$git_sha\`" >> $GITHUB_STEP_SUMMARY
deploy:
needs: [build_api_container, build_ui_container]
if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
SSH_USER: ${{ secrets.SSH_USER }}
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
GIT_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
steps:
- uses: actions/checkout@v3
- name: "SSH to server and deploy"
run: ./infra/ssh-to-server
deploy_workflow_dispatch:
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
SSH_USER: ${{ secrets.SSH_USER }}
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
GIT_SHA: ${{ github.event.inputs.commit_sha }}
steps:
- uses: actions/checkout@v3
- name: "SSH to server and deploy"
run: ./infra/ssh-to-server