-
Notifications
You must be signed in to change notification settings - Fork 0
123 lines (108 loc) · 3.97 KB
/
release.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
# https://github.com/docker/build-push-action/blob/master/docs/advanced/tags-labels.md
name: Release
on:
workflow_run:
workflows: [ Tests ]
types:
- completed
branches:
- main
jobs:
docker:
name: "Docker images"
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker meta PHP
id: meta-php
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
ghcr.io/eventpoints/customizer.site-php
# generate Docker tags based on the following events/attributes
tags: |
type=ref,event=branch
type=sha
no-cache: true
- name: Docker meta Caddy
id: meta-caddy
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
ghcr.io/eventpoints/customizer.site-caddy
# generate Docker tags based on the following events/attributes
tags: |
type=ref,event=branch
type=sha
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.REPO_ACCESS_TOKEN }}
- name: Build and push PHP
uses: docker/build-push-action@v5
with:
context: .
target: php
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta-php.outputs.tags }}
labels: ${{ steps.meta-php.outputs.labels }}
cache-from: type=gha, scope=${{ github.workflow }}
cache-to: type=gha, scope=${{ github.workflow }}
- name: Build and push Caddy
uses: docker/build-push-action@v5
with:
context: .
target: caddy
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta-caddy.outputs.tags }}
labels: ${{ steps.meta-caddy.outputs.labels }}
cache-from: type=gha, scope=${{ github.workflow }}
cache-to: type=gha, scope=${{ github.workflow }}
deploy:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
needs:
- docker
environment:
name: prod
url: https://customizer.site
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Copy docker-compose template
run: cp .deployment/docker-compose.production-template.yml .deployment/docker-compose.yml
# Iterate over secrets as JSON and replace possible placeholders
# Save output to the file to be processed
- name: Prepare docker-compose file
run: echo $SECRETS | jq --raw-output 'keys[]' | while read -r secretKey; do cat .deployment/docker-compose.yml | sed "s#__${secretKey}__#$(echo $SECRETS | jq --raw-output .${secretKey} | tr -d '\n\t')#" > .deployment/docker-compose.yml; done
env:
SECRETS: ${{ toJson(secrets) }}
- run: cat .deployment/docker-compose.yml
- name: Rsync Docker files
uses: burnett01/[email protected]
with:
switches: -azvr --exclude='docker-compose.production-template.yml'
path: ./.deployment/
remote_path: /customizer.site
remote_host: ${{ secrets.DEPLOY_HOST }}
remote_user: ${{ secrets.DEPLOY_USERNAME }}
remote_key: ${{ secrets.DEPLOY_PRIVATE_KEY }}
- uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USERNAME }}
key: ${{ secrets.DEPLOY_PRIVATE_KEY }}
script_stop: true
script: |
cd /customizer.site
docker-compose pull
docker-compose up -d