Skip to content

Commit

Permalink
chore: publish docker image to ghcr.io
Browse files Browse the repository at this point in the history
  • Loading branch information
William Petit committed Sep 13, 2024
1 parent a8ceb9a commit 84352fa
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,21 @@ jobs:
steps:
- if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
run: echo "flags=--snapshot" >> $GITHUB_ENV
- run: |
echo "REPOSITORY_OWNER=`echo ${{github.repository_owner}} | tr '[:upper:]' '[:lower:]'`" >> ${GITHUB_ENV}
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-go@v4
with:
go-version: 1.23
cache: true
- name: Docker Login
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
Expand Down
31 changes: 28 additions & 3 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ before:
hooks:
- go mod tidy

env:
- CGO_ENABLED=0

builds:
- targets: [go_first_class]
mod_timestamp: "{{ .CommitTimestamp }}"
Expand All @@ -14,9 +17,7 @@ builds:
# trims path
- -trimpath
ldflags:
# use commit date instead of current date as main.date
# only needed if you actually use those things in your main package, otherwise can be ignored.
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{ .CommitDate }}
- -s -w -extldflags '-static'
changelog:
sort: asc
filters:
Expand All @@ -25,3 +26,27 @@ changelog:
- "^test:"
release:
name_template: "v{{ .Version }}"

dockers:
- image_templates:
[
"ghcr.io/{{ .Env.REPOSITORY_OWNER }}/{{ .ProjectName }}:{{ .Version }}-amd64",
]
dockerfile: ./misc/docker/goreleaser/Dockerfile
build_flag_templates:
- --platform=linux/amd64
- --label=org.opencontainers.image.title={{ .ProjectName }}
- --label=org.opencontainers.image.description={{ .ProjectName }}
- --label=org.opencontainers.image.url=https://github.com/{{ .Env.REPOSITORY_OWNER }}/{{ .ProjectName }}
- --label=org.opencontainers.image.source=https://github.com/{{ .Env.REPOSITORY_OWNER }}/{{ .ProjectName }}
- --label=org.opencontainers.image.version={{ .Version }}
- --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.licenses=AGPL-3.0
docker_manifests:
- name_template: ghcr.io/{{ .Env.REPOSITORY_OWNER }}/{{ .ProjectName }}:{{ .Version }}
image_templates:
- ghcr.io/{{ .Env.REPOSITORY_OWNER }}/{{ .ProjectName }}:{{ .Version }}-amd64
- name_template: ghcr.io/{{ .Env.REPOSITORY_OWNER }}/{{ .ProjectName }}:latest
image_templates:
- ghcr.io/{{ .Env.REPOSITORY_OWNER }}/{{ .ProjectName }}:{{ .Version }}-amd64
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
DOCKER_IMAGES := $(shell find misc/docker/* -maxdepth 1 -type d -printf "%f\n")
DOCKER_IMAGES := $(shell find misc/docker/* -maxdepth 1 -type d -not -name goreleaser -printf "%f\n")
REPOSITORY_OWNER ?=

build:
CGO_ENABLED=0 go build -o ./bin/libra ./cmd/libra
Expand All @@ -12,4 +13,4 @@ docker-image-%:
docker build -t libra:$*-latest -f misc/docker/$*/Dockerfile .

release:
curl -sfL https://goreleaser.com/static/run | bash -s -- release --auto-snapshot --clean
curl -sfL https://goreleaser.com/static/run | REPOSITORY_OWNER=$(REPOSITORY_OWNER) bash -s -- release --auto-snapshot --clean
3 changes: 3 additions & 0 deletions misc/docker/goreleaser/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
ENTRYPOINT ["/libra"]
COPY libra /

0 comments on commit 84352fa

Please sign in to comment.