Skip to content

Commit bffcfd9

Browse files
ci: publishing Docker image (#225)
1 parent 68df7be commit bffcfd9

File tree

6 files changed

+84
-16
lines changed

6 files changed

+84
-16
lines changed

.github/workflows/continuous-delivery.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
# https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs
88
permissions:
99
contents: write
10+
packages: write
1011

1112
jobs:
1213
publish-binary:
@@ -19,6 +20,7 @@ jobs:
1920
run: make publish-binary RELEASE="${GITHUB_REF_NAME}"
2021
env:
2122
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by GitHub Actions.
23+
2224
publish-crate:
2325
name: Publish Crate
2426
runs-on: ubuntu-latest
@@ -29,3 +31,20 @@ jobs:
2931
run: make publish-crate
3032
env:
3133
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
34+
35+
publish-docker:
36+
name: Publish Docker Image
37+
runs-on: ubuntu-latest
38+
steps:
39+
- name: Checkout code.
40+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
41+
- name: Set up Docker Buildx
42+
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3
43+
- name: Login to GitHub Container Registry
44+
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3
45+
with:
46+
registry: ghcr.io
47+
username: ${{ github.actor }}
48+
password: ${{ secrets.GITHUB_TOKEN }}
49+
- name: Publish Docker Image
50+
run: make publish-docker RELEASE="${GITHUB_REF_NAME}"

.github/workflows/continuous-integration.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,6 @@ jobs:
4444
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
4545
- name: Unit test.
4646
run: make unit-test
47-
static-binary-test:
48-
name: Static Binary Test
49-
runs-on: ubuntu-latest
50-
steps:
51-
- name: Checkout code.
52-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
53-
- name: Static binary test.
54-
run: make static-binary-test
5547
end-to-end-test:
5648
name: End to End Test
5749
runs-on: ubuntu-latest

.github/workflows/dogfood.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Dogfood
2+
3+
on: pull_request
4+
5+
permissions:
6+
contents: read
7+
8+
jobs:
9+
docker:
10+
name: Docker
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code.
14+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
15+
with:
16+
ref: ${{ github.event.pull_request.head.sha }}
17+
fetch-depth: 0
18+
- name: Dogfooding Docker
19+
run: make dogfood-docker FROM="origin/${{ github.base_ref }}"

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM alpine:3.22.0@sha256:8a1f59ffb675680d47db6337b49d22281a139e9d709335b492be023728e11715
2+
3+
RUN apk add --no-cache \
4+
git=2.49.0-r0
5+
6+
COPY ./target/x86_64-unknown-linux-musl/release/conventional_commits_next_version /usr/local/bin/
7+
8+
WORKDIR /workspace
9+
10+
ENTRYPOINT ["conventional_commits_next_version"]

Makefile

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
UID := $(shell id -u)
33
GID := $(shell id -g)
44

5-
.PHONY: check-clean-git-history check-conventional-commits-linting check-rust-formatting check-python-formatting check-yaml-formatting fix-rust-formatting fix-python-formatting fix-yaml-formatting check-rust-linting check-github-actions-workflows-linting compile unit-test static-binary-test end-to-end-test publish-binary publish-crate
5+
.PHONY: check-clean-git-history check-conventional-commits-linting check-rust-formatting check-python-formatting check-yaml-formatting fix-rust-formatting fix-python-formatting fix-yaml-formatting check-rust-linting check-github-actions-workflows-linting compile unit-test end-to-end-test publish-binary publish-crate dogfood-docker publish-docker
66

77
# renovate: depName=ghcr.io/developerc286/clean_git_history
88
CLEAN_GIT_HISTORY_VERSION=1.0.4@sha256:5783341a3377a723e409e72b9ec0826a75ba944288d030978355de05ef65b186
@@ -27,7 +27,7 @@ SHFMT_VERSION=v3.11.0-alpine@sha256:394d755b6007056a2e6d7537ccdbdcfca01b9855ba91
2727

2828
check-shell-formatting:
2929
docker pull mvdan/shfmt:$(SHFMT_VERSION)
30-
docker run --rm -v $(PWD):/workspace -w /workspace -u $(UID):$(GID) mvdan/shfmt:$(SHFMT_VERSION) --simplify --diff ci/*
30+
docker run --rm -v $(PWD):/workspace -w /workspace -u $(UID):$(GID) mvdan/shfmt:$(SHFMT_VERSION) --simplify --diff ci/*
3131

3232
check-python-formatting:
3333
docker build -t check-python-formatting -f ci/check-python-formatting.Dockerfile .
@@ -43,7 +43,7 @@ fix-rust-formatting:
4343

4444
fix-shell-formatting:
4545
docker pull mvdan/shfmt:$(SHFMT_VERSION)
46-
docker run --rm -v $(PWD):/workspace -w /workspace -u $(UID):$(GID) mvdan/shfmt:$(SHFMT_VERSION) --simplify --write ci/*
46+
docker run --rm -v $(PWD):/workspace -w /workspace -u $(UID):$(GID) mvdan/shfmt:$(SHFMT_VERSION) --simplify --write ci/*
4747

4848
fix-python-formatting:
4949
docker build -t fix-python-formatting -f ci/fix-python-formatting.Dockerfile .
@@ -75,18 +75,25 @@ unit-test:
7575
docker build -t unit-test -f ci/unit-test.Dockerfile .
7676
docker run --rm -v $(PWD):/workspace -u $(UID):$(GID) unit-test
7777

78-
static-binary-test: compile
79-
docker run --rm -v $(PWD):/workspace -u $(UID):$(GID) compile --release
80-
./target/x86_64-unknown-linux-musl/release/conventional_commits_next_version --help
81-
8278
end-to-end-test: compile
8379
docker build -t end-to-end-test -f ci/end-to-end-test.Dockerfile .
8480
docker run --rm -v $(PWD):/workspace -u $(UID):$(GID) end-to-end-test
8581

86-
publish-binary: static-binary-test
82+
release:
83+
docker build -t compile -f ci/compile.Dockerfile .
84+
docker run --rm -v $(PWD):/workspace -u $(UID):$(GID) compile --release
85+
86+
publish-binary: release
8787
docker build -t publish-binary -f ci/publish-binary.Dockerfile .
8888
docker run --rm -v $(PWD):/workspace -u $(UID):$(GID) -e GH_TOKEN publish-binary $(RELEASE)
8989

9090
publish-crate:
9191
docker build -t publish-crate -f ci/publish-crate.Dockerfile .
9292
docker run --rm -v $(PWD):/workspace -u $(UID):$(GID) -e CARGO_REGISTRY_TOKEN publish-crate
93+
94+
dogfood-docker: release
95+
docker build -t conventional-commits-linter -f Dockerfile .
96+
docker run --rm -v $(PWD):/workspace -u $(UID):$(GID) conventional-commits-linter --from-version v1.0.0 $(FROM)
97+
98+
publish-docker: release
99+
./ci/publish-docker.sh ${RELEASE}

ci/publish-docker.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env sh
2+
3+
set -o errexit
4+
set -o xtrace
5+
6+
if [ $# -eq 0 ]; then
7+
echo "Usage: $0 <release>"
8+
exit 1
9+
fi
10+
11+
RELEASE="$1"
12+
REPOSITORY="$(basename $(git rev-parse --show-toplevel))"
13+
IMAGE="ghcr.io/developerc286/${REPOSITORY}"
14+
15+
docker build --tag "${IMAGE}:${RELEASE}" --file Dockerfile .
16+
docker push "${IMAGE}:${RELEASE}"
17+
18+
if [ "${RELEASE#v}" != "${RELEASE}" ]; then
19+
docker tag "${IMAGE}:${RELEASE}" "${IMAGE}:${RELEASE#v}"
20+
docker push "${IMAGE}:${RELEASE#v}"
21+
fi

0 commit comments

Comments
 (0)