-
Notifications
You must be signed in to change notification settings - Fork 0
49 lines (41 loc) · 1.39 KB
/
docker-image.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
name: Docker Image CI/CD
on:
push:
branches: [ "main" ]
tags:
- 'v*'
release:
types: [ published ]
pull_request:
branches: [ "main" ]
jobs:
login:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Define Docker Image Name
id: image_name
run: |
if [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == refs/tags/* ]]; then
echo "IMAGE_NAME=${{ github.repository }}:${{ github.ref_name }}" >> $GITHUB_ENV
elif [ "${{ github.event_name }}" == "release" ]; then
echo "IMAGE_NAME=${{ github.repository }}:${{ github.event.release.tag_name }}" >> $GITHUB_ENV
else
echo "IMAGE_NAME=${{ github.repository }}:$(echo $GITHUB_SHA | head -c7)" >> $GITHUB_ENV
fi
- name: Build the Docker image
run: |
docker build . --file Dockerfile --tag $IMAGE_NAME
- name: Push the Docker image
run: |
docker push $IMAGE_NAME
- name: Tag image as latest
if: github.ref == 'refs/heads/main'
run: |
docker tag $IMAGE_NAME ${{ github.repository }}:latest
docker push ${{ github.repository }}:latest