Skip to content

Commit 7b45ca7

Browse files
authored
Merge pull request #193 from evolvingweb/fix-ci-build
Fix Github action to build and push Docker image.
2 parents 42e22cb + 2f7d2ed commit 7b45ca7

1 file changed

Lines changed: 37 additions & 46 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 37 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,48 @@
1-
name: Build and Push Docker Image to Docker Hub
1+
name: Build and push to DockerHub
22

33
on:
44
push:
5-
branches: [ "master" ]
5+
tags:
6+
- 'v[0-9]+.[0-9]+.[0-9]+'
67

78
env:
89
REGISTRY: docker.io
910
IMAGE_NAME: ${{ github.repository }}
1011

1112
jobs:
12-
build:
13-
runs-on: ubuntu-latest
14-
15-
steps:
16-
- uses: actions/checkout@v3
17-
- name: Build the Docker image
18-
run: docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} .
19-
20-
test:
13+
build-deploy:
2114
runs-on: ubuntu-latest
15+
if: startsWith(github.event.ref, 'refs/tags/v')
2216
steps:
23-
- uses: actions/checkout@v3
24-
- name: Test the Docker image
25-
run: docker run --rm -d ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
26-
needs: build
27-
28-
# push_to_registry:
29-
# name: Push Docker image to Docker Hub
30-
# runs-on: ubuntu-latest
31-
# needs: test
32-
# steps:
33-
# - name: Check out the repo
34-
# uses: actions/checkout@v3
35-
36-
# - name: Set up Docker Buildx
37-
# uses: docker/setup-buildx-action@v2
38-
39-
# - name: Log in to Docker Hub
40-
# uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
41-
# with:
42-
# username: ${{ secrets.DOCKER_USERNAME }}
43-
# password: ${{ secrets.DOCKER_PASSWORD }}
44-
45-
# - name: Extract metadata for Docker
46-
# id: meta
47-
# uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
48-
# with:
49-
# images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
50-
51-
# - name: Build and push Docker image
52-
# uses: docker/build-push-action@v2
53-
# with:
54-
# context: "{{defaultContext}}"
55-
# push: true
56-
# tags: ${{ steps.meta.outputs.tags }}
57-
# labels: ${{ steps.meta.outputs.labels }}
17+
- name: "Check out"
18+
uses: actions/checkout@v4
19+
20+
- name: "Set up Docker Buildx"
21+
uses: docker/setup-buildx-action@v3
22+
23+
- name: "Login to Docker Hub"
24+
uses: docker/login-action@v3
25+
with:
26+
username: ${{ secrets.DOCKERHUB_USERNAME }}
27+
password: ${{ secrets.DOCKERHUB_TOKEN }}
28+
29+
- name: "Extract metadata for Docker"
30+
id: meta
31+
uses: docker/metadata-action@v5
32+
with:
33+
images: |
34+
${{ env.IMAGE_NAME }}
35+
tags: |
36+
type=semver,pattern={{version}}
37+
38+
- name: "Test Docker image"
39+
run: |
40+
docker run --rm -d ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
41+
42+
- name: "Build and push"
43+
uses: docker/build-push-action@v6
44+
with:
45+
context: .
46+
push: true
47+
tags: ${{ steps.meta.outputs.tags }}
48+
labels: ${{ steps.meta.outputs.labels }}

0 commit comments

Comments
 (0)