-
Notifications
You must be signed in to change notification settings - Fork 2
112 lines (90 loc) · 3.17 KB
/
ci.yml
File metadata and controls
112 lines (90 loc) · 3.17 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
defaults:
run:
shell: "bash"
name: "CI"
on:
push:
branches: ["main"]
tags: ["*"]
pull_request:
branches: ["main"]
jobs:
build:
name: "Verify that Docker image build well"
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v4.2.2"
- name: "Cache Docker layers"
uses: "actions/cache@v4.2.4"
with:
path: "/tmp/.buildx-cache"
key: "${{ runner.os }}-buildx-${{ github.sha }}"
restore-keys:
${{ runner.os }}-buildx-
- name: "Login to Docker Hub"
uses: "docker/login-action@v3.5.0"
with:
username: "${{ secrets.DOCKER_HUB_USERNAME }}"
password: "${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}"
- id: "buildx"
name: "Setup Docker Buildx"
uses: "docker/setup-buildx-action@v3.11.1"
- id: "docker_build"
name: "Build Docker image"
uses: "docker/build-push-action@v6.18.0"
with:
builder: "${{ steps.buildx.outputs.name }}"
context: "./"
file: "./Dockerfile"
push: false
tags: "${{ secrets.DOCKER_HUB_USERNAME }}/${{ github.event.repository.name }}:latest"
cache-from: "type=local,src=/tmp/.buildx-cache"
cache-to: "type=local,dest=/tmp/.buildx-cache"
- name: "Docker image digest"
run: "echo ${{ steps.docker_build.outputs.digest }}"
deploy:
needs: ["build"]
name: "Push Docker image to the Docker Hub"
if: "${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') }}"
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v4.2.2"
- name: "Cache Docker layers"
uses: "actions/cache@v4.2.4"
with:
path: "/tmp/.buildx-cache"
key: "${{ runner.os }}-buildx-${{ github.sha }}"
restore-keys:
${{ runner.os }}-buildx-
- name: "Login to Docker Hub"
uses: "docker/login-action@v3.5.0"
with:
username: "${{ secrets.DOCKER_HUB_USERNAME }}"
password: "${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}"
- id: "buildx"
name: "Setup Docker Buildx"
uses: "docker/setup-buildx-action@v3.11.1"
- id: "deploy_info"
name: "Setup deploy info"
run: |
set -euo pipefail
base_tag_name="${{ secrets.DOCKER_HUB_USERNAME }}/${{ github.event.repository.name }}"
tag_name="${base_tag_name}:latest"
if [ "${GITHUB_REF::10}" = "refs/tags/" ]; then
git_tag_name="${GITHUB_REF:10}"
tag_name="${base_tag_name}:${git_tag_name}"
fi
echo "::set-output name=tag_name::${tag_name}"
- id: "docker_build"
name: "Build & push Docker image"
uses: "docker/build-push-action@v6.18.0"
with:
builder: "${{ steps.buildx.outputs.name }}"
context: "./"
file: "./Dockerfile"
push: true
tags: "${{ steps.deploy_info.outputs.tag_name }}"
cache-from: "type=local,src=/tmp/.buildx-cache"
cache-to: "type=local,dest=/tmp/.buildx-cache"
- name: "Docker image digest"
run: "echo ${{ steps.docker_build.outputs.digest }}"