Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# .github/release.yml

changelog:
exclude:
labels:
- ignore-for-release
categories:
- title: Breaking Changes 🛠️
labels:
- breaking-change
- title: Exciting New Features 🎉
labels:
- enhancement
- title: Other Changes
labels:
- "*"
84 changes: 84 additions & 0 deletions .github/workflows/docker-build-publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Docker Build and Publish

on:
push:
branches: ["main"]
# Publish semver tags as releases.
tags: ["v*.*.*"]
pull_request:
branches: ["main"]

# Only allow a single running job for each PR/tag/branch
# and cancel any running jobs if a new one is created on top of it
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

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

jobs:
lint-build-publish:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write
attestations: write
id-token: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Lint
run: make lint

- name: Log in to the Container registry
uses: docker/login-action@v3.4.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5.7.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
id: push
uses: docker/build-push-action@v6.16.0
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Export release tag
if: github.event_name == 'push' && startsWith( github.ref, 'refs/tags/' )
run: echo "RELEASE_TAG=${GITHUB_REF_NAME}" >> $GITHUB_ENV

- name: Create release
if: github.event_name == 'push' && startsWith( github.ref, 'refs/tags/' )
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
try {
const response = await github.rest.repos.createRelease({
draft: false,
generate_release_notes: true,
name: process.env.RELEASE_TAG,
owner: context.repo.owner,
prerelease: false,
repo: context.repo.repo,
tag_name: process.env.RELEASE_TAG,
});
core.exportVariable('RELEASE_ID', response.data.id);
core.exportVariable('RELEASE_UPLOAD_URL', response.data.upload_url);
} catch (error) {
core.setFailed(error.message);
}
24 changes: 24 additions & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# MD013/line-length - Line length
MD013:
# Number of characters
line_length: 120
# Number of characters for headings
heading_line_length: 80
# Number of characters for code blocks
code_block_line_length: 100
# Include code blocks
code_blocks: true
# Include tables
tables: false
# Include headings
headings: true
# Include headings
headers: true
# Strict length checking
strict: false
# Stern length checking
stern: false

# MD041/first-line-heading/first-line-h1 First line in a file should be a top-level
# This complains about our github badges
MD041: false
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This is a very simple Dockerfile, it's contents aren't important, as this repo is mainly for showing how to setup the
# CI for docker image publishing repos

FROM scratch

COPY ./README.md /README.md
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# docker-image-example-template
Template repository for building a docker image, including all of the GitHub actions to verify and publish the image.

Template repository for building a docker image including all of the GitHub actions to verify and publish the image.
41 changes: 41 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

# These variables are used for controlling how the image gets tagged when it's built, and they can be overridden when
# the call to the make command is made
IMAGE_NAME = ghcr.io/jrwagz/docker-image-example-template

# Here we default to an image tag that makes it obvious that it was a local build, and that it isn't coming from CI
IMAGE_TAG:=$(shell whoami)-$(shell git describe --always)-dirty

# These variables control what images and tags are used for the various linting tasks
MD_LINT_IMAGE:=ghcr.io/igorshubovych/markdownlint-cli:v0.44.0
DOCKERFILE_LINT_IMAGE:=ghcr.io/hadolint/hadolint:v2.12.0
DIVE_IMAGE:=ghcr.io/wagoodman/dive:v0.13.1

.PHONY: build
build:
docker build -t $(IMAGE_NAME):$(IMAGE_TAG) .
docker run --rm -it \
-v /var/run/docker.sock:/var/run/docker.sock \
-v "$(PWD)":"$(PWD)" \
-w "$(PWD)" \
-e CI=true \
$(DIVE_IMAGE) $(IMAGE_NAME):$(IMAGE_TAG)
@echo SUCCESS $(FULL_NAME):$(IMAGE_TAG) is built and has been scanned by dive

MD_FILES:=$(shell find . -name "*.md")
.PHONY: lint_markdown
lint_markdown:
docker run --rm \
-v "${PWD}":"${PWD}" \
-w "${PWD}" \
$(MD_LINT_IMAGE) $(MD_FILES)

.PHONY: lint_dockerfile
lint_dockerfile:
docker run --rm -i $(DOCKERFILE_LINT_IMAGE) < Dockerfile

# Aliases
.PHONY: lint
lint: lint_dockerfile lint_markdown
.PHONY: ready
ready: lint build