-
Notifications
You must be signed in to change notification settings - Fork 0
113 lines (100 loc) · 3.17 KB
/
deploy.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
name: Deploy
on:
push:
branches:
- main
env:
DOMAIN: ${{ vars.DOMAIN }}
IMAGE_NAME: ${{ github.repository }}
REGISTRY: ghcr.io
STACK_NAME: swarmy
jobs:
publish-images:
name: Publish `${{ matrix.name }}` image
runs-on: ubuntu-latest
strategy:
matrix:
include:
- name: api
- name: web
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/${{ matrix.name }}
tags: |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=sha
- name: Build & push image
uses: docker/build-push-action@v5
with:
context: .
file: ./services/${{ matrix.name }}/Dockerfile
labels: ${{ steps.meta.outputs.labels }}
push: true
tags: ${{ steps.meta.outputs.tags }}
deploy:
name: Deploy
runs-on: ubuntu-latest
needs:
- publish-images
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure Docker context
uses: amirmarmul/docker-context-ssh-action@v1
with:
context-name: ${{ env.STACK_NAME }}
context-use: true
ssh-host: ${{ secrets.SSH_HOSTNAME }}
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
ssh-username: ${{ secrets.SSH_USERNAME }}
- name: Deploy stack
env:
CLOUDFLARE_DNS_API_TOKEN: ${{ secrets.CLOUDFLARE_DNS_API_TOKEN }}
CLOUDFLARE_EMAIL: ${{ secrets.CLOUDFLARE_EMAIL }}
DOMAIN: ${{ env.DOMAIN }}
run: docker stack deploy -c infra/config/compose.yml ${{ env.STACK_NAME }} --with-registry-auth
update-services:
name: Update `${{ matrix.name }}` service
runs-on: ubuntu-latest
needs:
- deploy
strategy:
matrix:
include:
- name: api
image: ghcr.io/nurodev/swarmy/api
- name: web
image: ghcr.io/nurodev/swarmy/web
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Configure Docker context
uses: amirmarmul/docker-context-ssh-action@v1
with:
context-name: ${{ env.STACK_NAME }}
context-use: true
ssh-host: ${{ secrets.SSH_HOSTNAME }}
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
ssh-username: ${{ secrets.SSH_USERNAME }}
- name: Update `${{ matrix.name }}` service
run: docker service update --image ${{ matrix.image }} ${{ env.STACK_NAME }}_${{ matrix.name }} --with-registry-auth