|
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 |
4 | 2 | on: |
5 | | - # push: # debug |
| 3 | + |
| 4 | + # publish on releases (tagged as "x.y.z" - "v" prefix is removed) |
6 | 5 | release: |
7 | 6 | types: [ published ] |
8 | | - |
9 | | - # Allows you to run this workflow manually from the Actions tab |
10 | | - workflow_dispatch: |
11 | 7 |
|
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 |
23 | 12 |
|
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" |
28 | 16 |
|
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 |
35 | 19 |
|
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