-
Notifications
You must be signed in to change notification settings - Fork 1
92 lines (76 loc) · 2.44 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
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
name: Docker Image CI
on:
pull_request:
branches:
- master
- staging
types:
- opened
- reopened
- synchronize
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
docker-ci-setup:
runs-on: ubuntu-24.04
permissions:
contents: read
timeout-minutes: 5
outputs:
ENVIRONMENT: ${{ steps.output.outputs.ENVIRONMENT }}
steps:
- name: set target branch
id: target
run: |
echo "TARGET_REF=refs/heads/${{ github.base_ref }}" >> "$GITHUB_ENV"
- name: staging
if: ${{ env.TARGET_REF == 'refs/heads/staging' }}
run: |
echo "ENVIRONMENT=staging" >> "$GITHUB_ENV"
- name: production
if: ${{ env.TARGET_REF == 'refs/heads/master' }}
run: |
echo "ENVIRONMENT=production" >> "$GITHUB_ENV"
- name: Error
if: ${{ env.TARGET_REF != 'refs/heads/master' && env.TARGET_REF != 'refs/heads/staging' }}
run: |
echo "[ERROR] Invalid target branch: ${{ env.TARGET_REF }}. Skipping deployment."
exit 1
- name: Output environment
id: output
run: |
echo "ENVIRONMENT=${{ env.ENVIRONMENT }}" >> "$GITHUB_OUTPUT"
docker-ci:
needs: docker-ci-setup
runs-on: ubuntu-24.04
permissions:
contents: read
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 # v3.8.0
- name: Create image tag
id: tag
run: |
SHA=${{github.sha}}
TAG="${{vars.IMAGE}}:$(TZ=UTC-9 date +'%Y%m')-${SHA:0:7}"
echo "TAG_FOR_PULL=${TAG}" >> "$GITHUB_OUTPUT"
if [ "${{ needs.docker-ci-setup.outputs.ENVIRONMENT }}" = "production" ]; then
LATEST="${{vars.IMAGE}}:latest"
echo "TAGS=${TAG},${LATEST}" >> "$GITHUB_OUTPUT"
else
echo "TAGS=${TAG}" >> "$GITHUB_OUTPUT"
fi
echo "Generated image tag: ${TAG}"
- name: Build
uses: docker/build-push-action@ca877d9245402d1537745e0e356eab47c3520991 # v6.13.0
with:
context: .
file: ./Dockerfile
push: false
tags: ${{ steps.tag.outputs.TAGS }}
cache-from: type=gha
cache-to: type=gha, mode=max