Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: build and push new prebuilt docker image #225

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions .dockerignore
@@ -0,0 +1,10 @@
#Ignore logs
logs/
*.log

#Ignore the git and cache folders
.git
.cache

#Ignore Temp files
*.tmp
77 changes: 77 additions & 0 deletions .github/workflows/build-docker-image.yml
@@ -0,0 +1,77 @@
name: Build & Publish Docker Image

# This workflow builds the prebuild.Dockerfile and publishes the image to the GitHub Container Registry if the build is successful.

on:
workflow_dispatch:
push:
branches:
- master

permissions:
packages: write
contents: read

env:
IMAGE_NAME: ${{ github.repository }}
REGISTRY: ghcr.io

jobs:
build:
timeout-minutes: 15
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Generate Docker Metadata
id: meta
uses: docker/metadata-action@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
images: |
ghcr.io/${{ github.actor }}/${{ github.repository }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha

- name: Set up QEMU To support build amd64 and arm64 images
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to DockerHub
sammcj marked this conversation as resolved.
Show resolved Hide resolved
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v3
id: docker_build
with:
push: ${{ github.event_name != 'pull_request' }}
context: .
file: ./prebuild.Dockerfile
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Output image, digest and metadata to summary
run: |
{
echo imageid: "${{ steps.docker_build.outputs.imageid }}"
echo digest: "${{ steps.docker_build.outputs.digest }}"
echo labels: "${{ steps.meta.outputs.labels }}"
echo tags: "${{ steps.meta.outputs.tags }}"
echo version: "${{ steps.meta.outputs.version }}"
} >> "$GITHUB_STEP_SUMMARY"
8 changes: 7 additions & 1 deletion .github/workflows/lint.yml
@@ -1,6 +1,7 @@
name: Lint

on:
workflow_dispatch:
pull_request:
types:
- opened
Expand All @@ -25,7 +26,7 @@ jobs:
reporter: github-pr-review
level: warning
path: .
pattern: '*.sh'
pattern: "*.sh"
fail_on_error: true

lint-dockerfile:
Expand All @@ -52,3 +53,8 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
reporter: github-pr-review
github_token: ${{ secrets.GITHUB_TOKEN }}
tool_name: actionlint
level: warning
fail_on_error: true
filter_mode: added
6 changes: 4 additions & 2 deletions .github/workflows/main.yml
@@ -1,6 +1,7 @@
name: Bump version

on:
workflow_dispatch:
pull_request:
types:
- closed
Expand All @@ -10,11 +11,12 @@ on:
jobs:
bump-version:
if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: '0'
fetch-depth: "0"
ref: ${{ github.ref_name }}

- name: version-tag
id: tag
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/test.yml
Expand Up @@ -2,6 +2,7 @@ name: Test
# This workflow tests the tag action and can be used on PRs to detect (some) breaking changes.

on:
workflow_dispatch:
pull_request:
types:
- opened
Expand All @@ -13,6 +14,7 @@ permissions:
pull-requests: write
checks: write
contents: read
packages: read

jobs:
test-action:
Expand All @@ -22,7 +24,7 @@ jobs:
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: '0'
fetch-depth: "0"

# Use the action to generate a tag for itself
- name: Test action main
Expand Down Expand Up @@ -86,4 +88,3 @@ jobs:
fi

# todo add test for #none bump

14 changes: 6 additions & 8 deletions Dockerfile
@@ -1,10 +1,8 @@
FROM node:16-alpine
LABEL "repository"="https://github.com/anothrNick/github-tag-action"
LABEL "homepage"="https://github.com/anothrNick/github-tag-action"
LABEL "maintainer"="Nick Sjostrom"

RUN apk --no-cache add bash git curl jq && npm install -g semver
# hadolint ignore=DL3007
FROM ghcr.io/anothrnick/github-tag-action:latest

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How will this play out with versioning of the action? When a user just declares the action like this

- name: Bump version and push tag
  uses: anothrNick/github-tag-action@1.55.0 # Don't use @master unless you're happy to test the latest version
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    WITH_V: true

Will GHA build version 1.55.0 of the action? Or will it be ghcr.io/anothrnick/github-tag-action:latest?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't retro build all past tags as images they will be built on demand by the local workflow

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And moving forward the tagged images will be available?


COPY entrypoint.sh /entrypoint.sh
LABEL "repository"="https://github.com/anothrnick/github-tag-action"
LABEL "homepage"="https://github.com/anothrnick/github-tag-action"
LABEL "maintainer"="Nick Sjostrom"

ENTRYPOINT ["/entrypoint.sh"]
# This Dockerfile is empty, it simply pulls a prebuilt image to speed up the Action.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -21,7 +21,7 @@ on:
- master
jobs:
build:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -45,7 +45,7 @@ on:
- master
jobs:
build:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
Expand Down
20 changes: 10 additions & 10 deletions action.yml
@@ -1,16 +1,16 @@
name: 'Github Tag Bump'
description: 'Bump and push git tag on merge'
author: 'Nick Sjostrom'
name: "Github Tag Bump"
description: "Bump and push git tag on merge"
author: "Nick Sjostrom"
runs:
using: 'docker'
image: 'Dockerfile'
using: "docker"
image: "Dockerfile"
outputs:
new_tag:
description: 'Generated tag'
description: "Generated tag"
tag:
description: 'The latest tag after running this action'
description: "The latest tag after running this action"
part:
description: 'The part of version which was bumped'
description: "The part of version which was bumped"
branding:
icon: 'git-merge'
color: 'purple'
icon: "git-merge"
color: "purple"
12 changes: 12 additions & 0 deletions prebuild.Dockerfile
@@ -0,0 +1,12 @@
FROM node:16-alpine

LABEL "repository"="https://github.com/anothrnick/github-tag-action"
LABEL "homepage"="https://github.com/anothrnick/github-tag-action"
LABEL "maintainer"="Nick Sjostrom"

# hadolint ignore=DL3016,DL3018
RUN apk --no-cache add bash git curl jq && npm install -g semver

COPY entrypoint.sh /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]