-
Notifications
You must be signed in to change notification settings - Fork 0
52 lines (44 loc) · 1.89 KB
/
GHCR-package.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
50
51
52
name: Build and Push Docker image to Github Container Registry
#on:
push:
branches:
- main
# Define the concurrency group
concurrency:
group: ghcr-build-${{ github.ref }}
cancel-in-progress: true
jobs:
build-and-push:
runs-on: ubuntu-latest
outputs:
image_tag: ${{ steps.set_output.outputs.image_tag }} # This will set the output for the job
steps:
- name: Check out the code
uses: actions/checkout@v2
- name: Log in to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GHCR_PAT }}
- name: Set lowercase repository owner and set image tag
id: set_output
run: |
REPO_OWNER=$(echo ${{ github.repository_owner }} | awk '{print tolower($0)}')
IMAGE_TAG="v1.2.1"
echo "REPO_OWNER=$REPO_OWNER" >> $GITHUB_ENV
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
echo "::set-output name=image_tag::$IMAGE_TAG" # This sets the output for image tag
- name: Build Docker image with specific tag
run: |
echo "Building Image: ghcr.io/${{ env.REPO_OWNER }}/ghcr-democicdapp:${{ env.IMAGE_TAG }}"
docker build . -t ghcr.io/${{ env.REPO_OWNER }}/ghcr-democicdapp:${{ env.IMAGE_TAG }}
- name: Push Docker image to GitHub Container Registry
run: |
echo "Pushing Image: ghcr.io/${{ env.REPO_OWNER }}/ghcr-democicdapp:${{ env.IMAGE_TAG }}"
docker push ghcr.io/${{ env.REPO_OWNER }}/ghcr-democicdapp:${{ env.IMAGE_TAG }}
- name: Tag and push Docker image with commit SHA
run: |
echo "Tagging and Pushing SHA: ${{ github.sha }}"
docker tag ghcr.io/${{ env.REPO_OWNER }}/ghcr-democicdapp:${{ env.IMAGE_TAG }} ghcr.io/${{ env.REPO_OWNER }}/ghcr-democicdapp:${{ github.sha }}
docker push ghcr.io/${{ env.REPO_OWNER }}/ghcr-democicdapp:${{ github.sha }}