Skip to content

Commit a3b1d05

Browse files
authored
Publish Docker image to ghcr.io
Use https://github.com/marketplace/actions/push-to-ghcr
1 parent fdaa45f commit a3b1d05

File tree

1 file changed

+18
-33
lines changed

1 file changed

+18
-33
lines changed
Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,25 @@
1-
name: Publish Docker image to pkg.github.com
2-
3-
# https://help.github.com/en/actions/reference/events-that-trigger-workflows
1+
name: Publish Docker image to ghcr.io
42
on:
5-
# push: # debug
3+
4+
# publish on releases (tagged as "x.y.z" - "v" prefix is removed)
65
release:
76
types: [ published ]
8-
9-
# Allows you to run this workflow manually from the Actions tab
10-
workflow_dispatch:
117

12-
jobs:
13-
build:
14-
# shared env variables
15-
env:
16-
DOCKER_REPOSITORY: docker.pkg.github.com
17-
DOCKER_IMAGE_NAME: elecena/python-php/base # follow OWNER/REPOSITORY/IMAGE_NAME schema
18-
DOCKER_PUSH_USER: elecena # this can be anything, Github token is used to log into the registry
19-
20-
runs-on: ubuntu-latest
21-
steps:
22-
- uses: actions/checkout@master
8+
# publish on pushes to the main branch (tagged as "master")
9+
push:
10+
branches:
11+
- master
2312

24-
# https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
25-
# e.g. docker.pkg.github.com/elecena/backend/bots-worker:1.9
26-
- name: Set Docker image name and release tag
27-
run: echo "DOCKER_TAG=${DOCKER_REPOSITORY}/${DOCKER_IMAGE_NAME}:${GITHUB_REF:10}" >> $GITHUB_ENV
13+
jobs:
14+
docker_publish:
15+
runs-on: "ubuntu-20.04"
2816

29-
- name: Build the Docker image
30-
env:
31-
# @see https://docs.docker.com/develop/develop-images/build_enhancements/
32-
COMPOSE_DOCKER_CLI_BUILD: "1"
33-
DOCKER_BUILDKIT: "1"
34-
run: docker build . --tag ${DOCKER_TAG} --build-arg GITHUB_SHA=${GITHUB_SHA}
17+
steps:
18+
- uses: actions/checkout@v2
3519

36-
# https://docs.github.com/en/free-pro-team@latest/actions/reference/authentication-in-a-workflow
37-
- name: Log in and publish to Registry
38-
run: |
39-
echo ${{ secrets.GITHUB_TOKEN }} | docker login ${DOCKER_REPOSITORY} -u ${DOCKER_PUSH_USER} --password-stdin
40-
docker push ${DOCKER_TAG}
20+
# https://github.com/marketplace/actions/push-to-ghcr
21+
- name: Build and publish a Docker image for ${{ github.repository }}
22+
uses: macbre/push-to-ghcr@v2
23+
with:
24+
image_name: ${{ github.repository }}
25+
github_token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)