From 266dcb476f6c713b18e0c1d28b58601f02dcf308 Mon Sep 17 00:00:00 2001 From: Antoine Aflalo <197810+Belphemur@users.noreply.github.com> Date: Tue, 27 Aug 2024 19:47:15 -0400 Subject: [PATCH] feat: add release workflow --- .github/workflows/release.yml | 41 +++++++++++++++ .goreleaser.yml | 98 +++++++++++++++++++++++++++++++++++ Dockerfile | 22 ++++++++ 3 files changed, 161 insertions(+) create mode 100644 .github/workflows/release.yml create mode 100644 .goreleaser.yml create mode 100644 Dockerfile diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..6367d4c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,41 @@ +# +# Releaser workflow setup +# https://goreleaser.com/ci/actions/ +# +name: release + +# run only on tags +on: + push: + tags: + - 'v*' + +permissions: + contents: write # needed to write releases + id-token: write # needed for keyless signing + packages: write # needed for ghcr access + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # this is important, otherwise it won't checkout the full tree (i.e. no previous tags) + - uses: actions/setup-go@v5 + with: + go-version: 1.23 + cache: true + - uses: sigstore/cosign-installer@v3.6.0 # installs cosign + - uses: anchore/sbom-action/download-syft@v0.17.2 # installs syft + - uses: docker/login-action@v3 # login to ghcr + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - uses: goreleaser/goreleaser-action@v6 # run goreleaser + with: + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..14f59a3 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,98 @@ +# .goreleaser.yml +project_name: CBZOptimizer +release: + github: + owner: belphemur + name: CBZOptimizer + changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' + - '^chore:' +builds: + - id: cbzoptimizer + main: main.go + goos: + - linux + goarch: + - amd64 + - arm64 + # ensures mod timestamp to be the commit timestamp + mod_timestamp: "{{ .CommitTimestamp }}" + flags: + # trims path + - -trimpath + ldflags: + - -s -w -X meta.Version={{.Version}} -X meta.Commit={{.Commit}} -X meta.Date={{ .CommitDate }} + env: + - CGO_ENABLED=0 +# config the checksum filename +# https://goreleaser.com/customization/checksum +checksum: + name_template: "checksums.txt" +# create a source tarball +# https://goreleaser.com/customization/source/ +source: + enabled: true +# proxies from the go mod proxy before building +# https://goreleaser.com/customization/gomod +gomod: + proxy: true +# creates SBOMs of all archives and the source tarball using syft +# https://goreleaser.com/customization/sbom +sboms: + - artifacts: archive + - id: source # Two different sbom configurations need two different IDs + artifacts: source +# create a docker image +# https://goreleaser.com/customization/docker +dockers: + - image_templates: + - "ghcr.io/belphemur/cbzoptimizer:latest" + - "ghcr.io/belphemur/cbzoptimizer:{{ .Version }}" + dockerfile: Dockerfile + build_flag_templates: + - "--pull" + - "--label=org.opencontainers.image.created={{.Date}}" + - "--label=org.opencontainers.image.name={{.ProjectName}}" + - "--label=org.opencontainers.image.revision={{.FullCommit}}" + - "--label=org.opencontainers.image.version={{.Version}}" + - "--label=org.opencontainers.image.source={{.GitURL}}" +# signs the checksum file +# all files (including the sboms) are included in the checksum, so we don't need to sign each one if we don't want to +# https://goreleaser.com/customization/sign +signs: + - cmd: cosign + env: + - COSIGN_EXPERIMENTAL=1 + certificate: "${artifact}.pem" + args: + - sign-blob + - "--output-certificate=${certificate}" + - "--output-signature=${signature}" + - "${artifact}" + - "--yes" # needed on cosign 2.0.0+ + artifacts: checksum + output: true +# signs our docker image +# https://goreleaser.com/customization/docker_sign +docker_signs: + - cmd: cosign + env: + - COSIGN_EXPERIMENTAL=1 + artifacts: images + output: true + args: + - "sign" + - "${artifact}" + - "--yes" # needed on cosign 2.0.0+ +archives: + - format: tar.gz + name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}" + files: + - LICENSE + - README.md + - CHANGELOG.md + - "CBZOptimizer" \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0b21736 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM alpine:latest +LABEL authors="Belphemur" +ENV USER=abc +ENV CONFIG_FOLDER=/config +ENV PUID=99 +ENV PGID=100 +RUN mkdir -p "${CONFIG_FOLDER}" && addgroup -g "${PGID}" "${USER}" && adduser \ + --disabled-password \ + --gecos "" \ + --home "$(pwd)" \ + --ingroup "${USER}" \ + --no-create-home \ + --uid "${PUID}" \ + "${USER}" && \ + chown ${PUID}:${GUID} /config "${CONFIG_FOLDER}" + +COPY CBZOptimizer /usr/local/bin/CBZOptimizer + +RUN apk add --no-cache inotify-tools && chmod +x /usr/local/bin/CBZOptimizer + +USER ${USER} +ENTRYPOINT ["/usr/local/bin/CBZOptimizer"] \ No newline at end of file