-
Notifications
You must be signed in to change notification settings - Fork 2
76 lines (67 loc) · 2.48 KB
/
deploy-dev.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
name: "Deployment"
on:
push:
branches: [master]
pull_request:
types: [opened, reopened, synchronize, closed]
pull_request_review:
types: [submitted]
schedule:
- cron: '12 20 12 * *'
jobs:
subdomain:
runs-on: ubuntu-latest
outputs:
output: ${{ steps.final.outputs.output }}
steps:
- name: Cancel if pull request is not approved
if: ${{ github.event_name == 'pull_request_review' && github.event.review.state != 'approved' }}
run: exit 1
- name: Checkout repository
uses: actions/checkout@v4
- name: Set SUBDOMAIN=pr#
if: ${{ github.event_name != 'push' }}
run: echo "SUBDOMAIN=pr${{ github.event.pull_request.number }}" >> $GITHUB_ENV
- name: Set SUBDOMAIN=master
if: ${{ github.event_name == 'push' }}
run: echo "SUBDOMAIN=master" >> $GITHUB_ENV
- name: Output
id: final
run: echo "::set-output name=output::${SUBDOMAIN}"
deploy:
needs: subdomain
runs-on: ubuntu-latest
env:
SUBDOMAIN: ${{ github.event.pull_request.number || 'master' }}
concurrency:
group: "deploy ${{ needs.subdomain.outputs.output }}"
cancel-in-progress: true
steps:
- name: Cancel if pull request is not approved
if: ${{ github.event_name == 'pull_request_review' && github.event.review.state != 'approved' }}
run: exit 1
- name: Checkout repository
uses: actions/checkout@v4
- name: Set SUBDOMAIN env var
run: echo "SUBDOMAIN=${{ needs.subdomain.outputs.output }}" >> $GITHUB_ENV
- name: Generate docker-compose.yml
run: envsubst < .ci/docker-compose.yml.tmpl | tee docker-compose-github.yml
- name: Set up SSH
run: |
mkdir -p ${HOME}/.ssh
echo "${{ secrets.DEV_SNAD_SSH_KEY }}" > ${HOME}/.ssh/id_rsa
ls -lk ${HOME}/.ssh/id_rsa
chmod 600 ${HOME}/.ssh/id_rsa
ssh-keyscan -t ssh-rsa dev.snad.space >> ${HOME}/.ssh/known_hosts
- name: Set up Docker context
run: docker context create dev-snad --docker "host=ssh://[email protected]"
- name: Stop
run: |
docker context use dev-snad
docker compose -f docker-compose-github.yml -p ${SUBDOMAIN} down
- name: Start
if: ${{ github.event.pull_request.state != 'closed' }}
run: |
docker context use dev-snad
docker compose -f docker-compose-github.yml -p ${SUBDOMAIN} build --build-arg GITHUB_SHA
docker compose -f docker-compose-github.yml -p ${SUBDOMAIN} up -d