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: pre-build dockerfile #201

Merged
merged 5 commits into from Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all 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 }}
IMAGE_TAG: ${{ github.sha }}
REGISTRY: ghcr.io

jobs:
build:
timeout-minutes: 15
runs-on: ubuntu-22.04
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: |
${{ env.IMAGE_NAME }}
ghcr.io/user${{ env.IMAGE_NAME }}
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
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
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 }}

- 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"
14 changes: 10 additions & 4 deletions .github/workflows/lint.yml
@@ -1,6 +1,7 @@
name: Lint

on:
workflow_dispatch:
pull_request:
types:
- opened
Expand All @@ -16,7 +17,7 @@ permissions:
jobs:
lint-bash:
name: Lint Bash scripts
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: reviewdog/action-shellcheck@v1
Expand All @@ -25,12 +26,12 @@ jobs:
reporter: github-pr-review
level: warning
path: .
pattern: '*.sh'
pattern: "*.sh"
fail_on_error: true

lint-dockerfile:
name: Lint Dockerfiles
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: hadolint
Expand All @@ -42,7 +43,7 @@ jobs:
hadolint_ignore: DL3016 DL3018 # Ignore pinning apk and npm packages to specific version with @

lint-actions:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Lint Github Actions
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 @@ -14,7 +15,8 @@ jobs:
steps:
- uses: actions/checkout@v3
with:
fetch-depth: '0'
fetch-depth: "0"
ref: ${{ github.ref_name }}

- name: version-tag
id: tag
Expand Down Expand Up @@ -46,4 +48,4 @@ jobs:
git push -f origin "$major"
# add vX as 1 is linked to short sha bug https://github.com/anothrNick/github-tag-action/actions/runs/3139501775/jobs/5099976842#step:1:35
git tag -f "v$major"
git push -f origin "v$major"
git push -f origin "v$major"
7 changes: 4 additions & 3 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,16 +14,17 @@ permissions:
pull-requests: write
checks: write
contents: read
packages: read

jobs:
test-action:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- name: Checkout
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

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.
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"]