Skip to content

Commit 8558114

Browse files
Update docker-publish.yml
1 parent ca4832e commit 8558114

File tree

1 file changed

+25
-61
lines changed

1 file changed

+25
-61
lines changed
Lines changed: 25 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,50 @@
1-
name: Docker
2-
3-
# This workflow uses actions that are not certified by GitHub.
4-
# They are provided by a third-party and are governed by
5-
# separate terms of service, privacy policy, and support
6-
# documentation.
1+
#
2+
name: Create and publish a Docker image with tags
73

4+
# Configures this workflow to run every time a change is pushed and have tags
85
on:
9-
#schedule:
10-
# - cron: '35 15 * * *'
116
push:
12-
branches: [ "main" ]
13-
# Publish semver tags as releases.
14-
tags: [ 'v*.*.*' ]
15-
#pull_request:
16-
# branches: [ "main" ]
17-
release:
18-
types: [published]
7+
tags:
8+
- '*'
199

10+
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
2011
env:
21-
# Use docker.io for Docker Hub if empty
2212
REGISTRY: ghcr.io
23-
# github.repository as <account>/<repo>
2413
#IMAGE_NAME: ${{ github.repository }}
25-
IMAGE_NAME: ghcr.io/justcoded/docsify_test
14+
IMAGE_NAME: ghcr.io/justcoded/docsify
2615

16+
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
2717
jobs:
28-
build:
18+
build-and-push-image:
2919
runs-on: ubuntu-latest
30-
#if: startsWith(github.ref, 'refs/tags/') # Running this job only for tags
31-
20+
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
3221
permissions:
3322
contents: read
3423
packages: write
35-
# This is used to complete the identity challenge
36-
# with sigstore/fulcio when running outside of PRs.
37-
id-token: write
38-
24+
#
3925
steps:
40-
- name: Extract branch name
41-
shell: bash
42-
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
43-
id: extract_branch
44-
4526
- name: Checkout repository
46-
uses: actions/checkout@v3
47-
48-
# Set up BuildKit Docker container builder to be able to build
49-
# multi-platform images and export cache
50-
# https://github.com/docker/setup-buildx-action
51-
- name: Set up Docker Buildx
52-
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
53-
54-
# Login against a Docker registry except on PR
55-
# https://github.com/docker/login-action
56-
- name: Log into registry ${{ env.REGISTRY }}
57-
if: github.event_name != 'pull_request'
58-
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
27+
uses: actions/checkout@v4
28+
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
29+
- name: Log in to the Container registry
30+
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
5931
with:
6032
registry: ${{ env.REGISTRY }}
6133
username: ${{ github.actor }}
6234
password: ${{ secrets.GITHUB_TOKEN }}
63-
64-
65-
# Extract metadata (tags, labels) for Docker
66-
# https://github.com/docker/metadata-action
67-
- name: Extract Docker metadata
35+
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
36+
- name: Extract metadata (tags, labels) for Docker
6837
id: meta
69-
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
38+
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
7039
with:
7140
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
72-
73-
74-
75-
# Build and push Docker image with Buildx (don't push on PR)
76-
# https://github.com/docker/build-push-action
41+
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
42+
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
43+
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
7744
- name: Build and push Docker image
78-
id: build-and-push
79-
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
45+
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
8046
with:
81-
image: ghcr.io/justcoded/docsify_test
8247
context: .
83-
push: ${{ github.event_name != 'pull_request' }}
84-
tags: ${{ steps.extract_branch.outputs.branch }}
85-
86-
48+
push: true
49+
tags: ${{ steps.meta.outputs.tags }}
50+
labels: ${{ steps.meta.outputs.labels }}

0 commit comments

Comments
 (0)