diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f9ba7f5..c7c01b8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,6 +19,8 @@ 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 @@ -26,6 +28,12 @@ jobs: 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 diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 538e9d9..1eb45e7 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -6,6 +6,9 @@ before: hooks: - go mod tidy +env: + - CGO_ENABLED=0 + builds: - targets: [go_first_class] mod_timestamp: "{{ .CommitTimestamp }}" @@ -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: @@ -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 diff --git a/Makefile b/Makefile index ed4bca2..2297e3a 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 \ No newline at end of file + curl -sfL https://goreleaser.com/static/run | REPOSITORY_OWNER=$(REPOSITORY_OWNER) bash -s -- release --auto-snapshot --clean \ No newline at end of file diff --git a/misc/docker/goreleaser/Dockerfile b/misc/docker/goreleaser/Dockerfile new file mode 100644 index 0000000..05e0716 --- /dev/null +++ b/misc/docker/goreleaser/Dockerfile @@ -0,0 +1,3 @@ +FROM scratch +ENTRYPOINT ["/libra"] +COPY libra / \ No newline at end of file