-
Notifications
You must be signed in to change notification settings - Fork 17
50 lines (42 loc) · 1.64 KB
/
docker-image.yaml
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
name: Build and Push Docker Image to GitHub Container Registry
on:
push:
branches:
- '**' # Matches pushes to all branches
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
# Checkout the code
- name: Checkout code
uses: actions/checkout@v3
# Log in to GitHub Container Registry
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Build the Docker image
- name: Build Docker image
run: |
docker build -t ghcr.io/${{ github.repository_owner }}/oldp:${{ github.sha }} .
# Tag the Docker image with the branch or tag name
- name: Tag Docker image with ref name
run: |
IMAGE_TAG=${GITHUB_REF_NAME//\//-}
docker tag ghcr.io/${{ github.repository_owner }}/oldp:${{ github.sha }} ghcr.io/${{ github.repository_owner }}/oldp:$IMAGE_TAG
# If the branch is 'master', tag the image as 'latest'
- name: Tag Docker image as latest if master
if: github.ref_name == 'master'
run: |
docker tag ghcr.io/${{ github.repository_owner }}/oldp:${{ github.sha }} ghcr.io/${{ github.repository_owner }}/oldp:latest
# Push all tags
- name: Push Docker images
run: |
docker push ghcr.io/${{ github.repository_owner }}/oldp:${{ github.sha }}
IMAGE_TAG=${GITHUB_REF_NAME//\//-}
docker push ghcr.io/${{ github.repository_owner }}/oldp:$IMAGE_TAG
if [ "${GITHUB_REF_NAME}" = "master" ]; then
docker push ghcr.io/${{ github.repository_owner }}/oldp:latest
fi