-
Notifications
You must be signed in to change notification settings - Fork 5
134 lines (116 loc) · 3.62 KB
/
cicd-tasks.yaml
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
name: CICD tasks
on:
push:
branches:
- '*'
paths:
- 'lib/**'
- 'tasks/**'
- 'api-services/**'
- 'pnpm*.yaml'
- 'package*.json'
- 'Dockerfile.tasks'
- '.dockerignore'
- '.github/workflows/**'
tags:
- 'v*'
pull_request:
paths:
- 'lib/**'
- 'tasks/**'
- 'api-services/**'
- 'pnpm*.yaml'
- 'package*.json'
- 'Dockerfile.tasks'
- '.dockerignore'
- '.github/workflows/**'
jobs:
build:
name: Build docker image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
IMAGE: ${{ env.IMAGE_NAME }}@${{ steps.docker-build-and-push.outputs.digest }}
steps:
- uses: actions/checkout@v4
- name: Lowercase github.repository_owner
run: |
echo "REPOSITORY_OWNER_LC=${REPOSITORY_OWNER,,}" >>${GITHUB_ENV}
env:
REPOSITORY_OWNER: ${{ github.repository_owner }}
- name: Image name
run: |
echo "IMAGE_NAME=ghcr.io/${{ env.REPOSITORY_OWNER_LC }}/web-app" >>${GITHUB_ENV}
- uses: docker/metadata-action@v4
id: meta
with:
images: ${{ env.IMAGE_NAME }}
tags: |
type=edge
type=ref,event=pr
type=ref,event=branch,prefix=branch-
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- uses: docker/setup-qemu-action@v2
- uses: docker/setup-buildx-action@v2
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: ${{ runner.os }}-buildx
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ github.token }}
- id: commit
uses: pr-mpt/actions-commit-hash@v2
with:
commit: "${{ github.sha }}"
- name: Build
uses: docker/build-push-action@v4
id: docker-build-and-push
with:
context: .
file: Dockerfile.tasks
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
build-args: |
VERSION=${{ steps.commit.outputs.short }}
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Check manifest
if: ${{ github.event_name != 'pull_request' }}
run: |
docker buildx imagetools inspect ${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
deploy:
name: Deploy to Fly
runs-on: ubuntu-latest
environment: staging
needs: build
concurrency:
group: ${{ github.workflow }}-${{ vars.FLY_APP }}
cancel-in-progress: true
if: ${{ github.event_name != 'pull_request' && github.ref_name == 'main' }}
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
steps:
- name: Setup flyctl
uses: superfly/flyctl-actions/setup-flyctl@master
- name: Deploy
run: flyctl deploy --config tasks/fly.toml --app $APP --image $IMAGE --remote-only
env:
APP: ${{ vars.FLY_APP }}
IMAGE: ${{ needs.build.outputs.IMAGE }}