-
Notifications
You must be signed in to change notification settings - Fork 0
110 lines (94 loc) · 3.54 KB
/
Copy pathdocker-image.yml
File metadata and controls
110 lines (94 loc) · 3.54 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
name: Docker Image
on:
push:
branches: ["main"]
paths:
- "api/**"
- "client/**"
- "Dockerfile.backend"
- "Dockerfile.frontend"
- "requirements.txt"
workflow_dispatch:
env:
IMAGE_NAME_FRONTEND: safe-lens-frontend
IMAGE_NAME_BACKEND: safe-lens-backend
jobs:
changes:
runs-on: ubuntu-latest
outputs:
backend: ${{ steps.filter.outputs.backend }}
frontend: ${{ steps.filter.outputs.frontend }}
steps:
- uses: actions/checkout@v4
- name: Detect changed paths
id: filter
uses: dorny/paths-filter@v3
with:
filters: |
backend:
- "api/**"
- "Dockerfile.backend"
- "requirements.txt"
frontend:
- "client/**"
- "Dockerfile.frontend"
build-backend:
runs-on: ubuntu-latest
needs: changes
if: ${{ github.event_name == 'workflow_dispatch' || needs.changes.outputs.backend == 'true' }}
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v4
- name: Build backend image
run: |
echo IMAGE_NAME_BACKEND=$IMAGE_NAME_BACKEND
docker build . --file Dockerfile.backend --tag $IMAGE_NAME_BACKEND
- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Push backend image
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME_BACKEND
# Change all uppercase characters to lowercase.
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip the git ref prefix from the version.
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip the "v" prefix from the tag name.
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Uses the Docker `latest` tag convention.
[ "$VERSION" == "main" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME_BACKEND $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
build-frontend:
runs-on: ubuntu-latest
needs: changes
if: ${{ github.event_name == 'workflow_dispatch' || needs.changes.outputs.frontend == 'true' }}
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v4
- name: Build frontend image
run: |
echo IMAGE_NAME_FRONTEND=$IMAGE_NAME_FRONTEND
docker build . --file Dockerfile.frontend --tag $IMAGE_NAME_FRONTEND
- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Push frontend image
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME_FRONTEND
# Change all uppercase characters to lowercase.
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip the git ref prefix from the version.
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip the "v" prefix from the tag name.
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Uses the Docker `latest` tag convention.
[ "$VERSION" == "main" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME_FRONTEND $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION