-
Notifications
You must be signed in to change notification settings - Fork 0
116 lines (99 loc) · 3.56 KB
/
Copy pathdeploy.yml
File metadata and controls
116 lines (99 loc) · 3.56 KB
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
name: Nitro CD
run-name: ${{ github.ref_name }}
permissions:
contents: write
packages: write
attestations: write
id-token: write
on:
release:
types:
- published
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true
env:
REPO: ${{ github.repository }}
USERNAME: ${{ vars.USERNAME }}
VERSION: ${{ github.ref_name }}
jobs:
build:
runs-on: ubuntu-latest
outputs:
image_name: ${{ steps.metadata.outputs.image_name }}
image_title: ${{ steps.metadata.outputs.image_title }}
buildtime: ${{ steps.metadata.outputs.buildtime }}
version: ${{ steps.metadata.outputs.version }}
steps:
- name: 📥 Checkout Repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 🐋 Set up QEMU
uses: docker/setup-qemu-action@v3
- name: 🐋 Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: 🐋 Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ env.REPO }}
docker.io/${{ env.REPO }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix=sha-,format=short
- name: 🏷️ Set tags as environment variable
id: metadata
run: |
echo "Setting metadata to env variables"
echo "image_name=${{ fromJSON(steps.meta.outputs.json).tags[0] }}" >> $GITHUB_OUTPUT
echo "image_title=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.title'] }}" >> $GITHUB_OUTPUT
echo "buildtime=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}" >> $GITHUB_OUTPUT
echo "version=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}" >> $GITHUB_OUTPUT
- name: 🐋 Log in to Github Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ env.USERNAME }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to DockerHub
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ env.USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: ⚙️ Build and Upload to Registries
id: push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ steps.metadata.outputs.version }}
BUILD_TIME=${{ steps.metadata.outputs.buildtime }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: 📝 Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ghcr.io/${{ env.REPO }}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: false
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: 🔀 Deploy to VPS
uses: appleboy/ssh-action@v1.1.0
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USERNAME }}
password: ${{ secrets.VPS_PASSWORD }}
script: |
cd ~/${{ env.REPO }}
curl -O https://raw.githubusercontent.com/${{ env.REPO }}/refs/heads/main/docker-compose.prod.yml
docker stack deploy --compose-file docker-compose.prod.yml unauth-api