-
Notifications
You must be signed in to change notification settings - Fork 0
67 lines (57 loc) · 2.14 KB
/
docker-ci.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
name: Docker Image CI
on:
workflow_run:
workflows: ["Test"]
types: [completed]
jobs:
build-and-push:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- uses: actions/checkout@v2
- name: Prepare
id: prep
run: |
OWNER=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
WEB_IMAGE=ghcr.io/$OWNER/hkrecruitment-web
API_IMAGE=ghcr.io/$OWNER/hkrecruitment-api
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
WEB_TAGS="$WEB_IMAGE:$VERSION,$WEB_IMAGE:latest"
API_TAGS="$API_IMAGE:$VERSION,$API_IMAGE:latest"
elif [[ $GITHUB_REF == refs/heads/main ]]; then
VERSION=main-$(git rev-parse --short ${{ github.sha }})
WEB_TAGS="$WEB_IMAGE:$VERSION,$WEB_IMAGE:latest"
API_TAGS="$API_IMAGE:$VERSION,$API_IMAGE:latest"
elif [[ $GITHUB_REF == refs/heads/dev ]]; then
VERSION=dev-$(git rev-parse --short ${{ github.sha }})
WEB_TAGS="$WEB_IMAGE:$VERSION,$WEB_IMAGE:test"
API_TAGS="$API_IMAGE:$VERSION,$API_IMAGE:test"
else
VERSION=$(git rev-parse --short ${{ github.sha }})
WEB_TAGS="$WEB_IMAGE:$VERSION"
API_TAGS="$API_IMAGE:$VERSION"
fi
echo "::set-output name=web_tags::$WEB_TAGS"
echo "::set-output name=api_tags::$API_TAGS"
shell: bash
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push web image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile_web
push: true
tags: ${{ steps.prep.outputs.web_tags }}
- name: Build and push api image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile_api
push: true
tags: ${{ steps.prep.outputs.api_tags }}