-
Notifications
You must be signed in to change notification settings - Fork 32
39 lines (32 loc) · 1.47 KB
/
docker-build.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
name: Build and Push Docker Image
on:
release:
types: [published] # Trigger the workflow on published releases
jobs:
build-and-push:
runs-on: ubuntu-latest # Use the latest Ubuntu runner
steps:
- name: Checkout the code
uses: actions/checkout@v3 # Check out the repository code
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2 # Set up Docker Buildx for multi-platform builds
- name: Log in to Docker Hub
uses: docker/login-action@v2 # Log in to Docker Hub using GitHub secrets
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract version from tag
id: extract_version # Extract the version number and fix format
run: |
# Extract version by removing "moosez-" and replacing ".0." with "0."
VERSION=$(echo ${GITHUB_REF##*/} | sed -E 's/moosez-v\.([0-9]+\.[0-9]+\.[0-9]+)/v\1/')
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Build and push Docker image
uses: docker/build-push-action@v5 # Build and push the Docker image
with:
context: . # Build context (current directory)
file: ./Dockerfile # Path to the Dockerfile
push: true # Push the image to Docker Hub
tags: | # Tags for the Docker image
${{ secrets.DOCKER_USERNAME }}/moosez:${{ env.VERSION }}
${{ secrets.DOCKER_USERNAME }}/moosez:latest