Skip to content

Commit b9755ff

Browse files
DOCKER_HUB_BASE_NAME
1 parent 6355b0b commit b9755ff

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Push Docker Image
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
env:
8+
DOCKER_BASE_NAME: ghcr.io/${{ github.repository }}
9+
DOCKER_HUB_BASE_NAME: ${{ github.repository }}
10+
11+
jobs:
12+
lint:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
- name: Unshallow
18+
run: git fetch --prune --unshallow
19+
push:
20+
runs-on: ubuntu-22.04
21+
needs: lint
22+
strategy:
23+
matrix:
24+
baseimage:
25+
- "alpine:3.17"
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v4
29+
- name: Set env
30+
run: |
31+
if [ "${{ github.event_name }}" = 'release' ]; then
32+
export TAG_NAME="${{ github.event.release.tag_name }}"
33+
else
34+
export TAG_NAME="latest"
35+
fi
36+
echo "PKG_TAG=${DOCKER_BASE_NAME}:${TAG_NAME}" >> $GITHUB_ENV
37+
echo "HUB_TAG=${DOCKER_HUB_BASE_NAME}:${TAG_NAME}" >> $GITHUB_ENV
38+
- name: Build ${{ matrix.baseimage }} base image
39+
run: |
40+
docker build . -t "${PKG_TAG}" --build-arg BASE_IMAGE="${{ matrix.baseimage }}"
41+
docker tag "${PKG_TAG}" "${HUB_TAG}"
42+
- name: Login to Registries
43+
if: github.event_name != 'pull_request'
44+
env:
45+
PERSONAL_GITHUB_TOKEN: ${{ secrets.PERSONAL_GITHUB_TOKEN }}
46+
DCKR_PAT: ${{ secrets.DCKR_PAT }}
47+
run: |
48+
echo "${PERSONAL_GITHUB_TOKEN}" | docker login ghcr.io -u trinhminhtriet --password-stdin
49+
echo "${DCKR_PAT}" | docker login -u trinhminhtriet --password-stdin
50+
- name: Push to GitHub Packages
51+
if: github.event_name != 'pull_request'
52+
run: docker push "${PKG_TAG}"
53+
- name: Push to Docker Hub
54+
if: github.event_name != 'pull_request'
55+
run: docker push "${HUB_TAG}"

0 commit comments

Comments
 (0)