Skip to content

Commit 811cd0e

Browse files
ci: refactor docker ci
1 parent eef7151 commit 811cd0e

1 file changed

Lines changed: 36 additions & 41 deletions

File tree

.github/workflows/ci.yml

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,58 @@
11
name: ci
22

33
on:
4-
schedule:
5-
- cron: "0 0 1 * *"
64
push:
7-
branches:
8-
- "**"
9-
tags:
10-
- "v*.*.*"
5+
branches: [ "dev", "main" ]
116
pull_request:
12-
branches:
13-
- "main"
7+
branches: [ "dev", "main" ]
148

159
env:
16-
docker_user: ${{ secrets.DOCKERHUB_USERNAME }}
17-
app_name: ${{ vars.APP_NAME }}
10+
# Use docker.io for Docker Hub if empty
11+
REGISTRY: docker.io
12+
# github.repository as <account>/<repo>
13+
IMAGE_NAME: ${{ github.repository }}
1814

1915
jobs:
20-
docker:
21-
strategy:
22-
fail-fast: true
16+
build:
2317
runs-on: ubuntu-latest
2418
steps:
25-
- name: Checkout
19+
- uses: actions/checkout@v3
20+
- name: Build the Docker image
21+
run: docker-compose build --no-cache --force-rm
22+
23+
test:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v2
27+
- name: Test the Docker image
28+
run: docker-compose up -d
29+
30+
push_to_registry:
31+
name: Push Docker image to Docker Hub
32+
runs-on: ubuntu-latest
33+
steps:
34+
- name: Check out the repo
2635
uses: actions/checkout@v3
27-
- name: Docker meta
28-
id: meta
29-
uses: docker/metadata-action@v4
30-
with:
31-
# list of Docker images to use as base name for tags
32-
images: |
33-
${{ env.docker_user }}/${{ env.app_name }}
34-
# generate Docker tags based on the following events/attributes
35-
tags: |
36-
type=schedule
37-
type=ref,event=branch
38-
type=ref,event=pr
39-
type=semver,pattern={{version}}
40-
type=semver,pattern={{major}}.{{minor}}
41-
type=semver,pattern={{major}}
42-
type=sha
43-
44-
- name: Set up QEMU
45-
uses: docker/setup-qemu-action@v3
4636

4737
- name: Set up Docker Buildx
48-
uses: docker/setup-buildx-action@v3
38+
uses: docker/setup-buildx-action@v2
4939

50-
- name: Login to Docker Hub
51-
if: github.event_name != 'pull_request'
52-
uses: docker/login-action@v2
40+
- name: Log in to Docker Hub
41+
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
5342
with:
5443
username: ${{ secrets.DOCKERHUB_USERNAME }}
5544
password: ${{ secrets.DOCKERHUB_TOKEN }}
5645

57-
- name: Build and push
58-
uses: docker/build-push-action@v5
46+
- name: Extract metadata (tags, labels) for Docker
47+
id: meta
48+
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
49+
with:
50+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
51+
52+
- name: Build and push Docker image
53+
uses: docker/build-push-action@v2
5954
with:
60-
context: .
61-
push: ${{ github.event_name != 'pull_request' }}
55+
context: "{{defaultContext}}"
56+
push: true
6257
tags: ${{ steps.meta.outputs.tags }}
6358
labels: ${{ steps.meta.outputs.labels }}

0 commit comments

Comments
 (0)