From 050d3e6cd29376a9acc301492b2a649be3dd3a95 Mon Sep 17 00:00:00 2001 From: Wyatt Gill Date: Fri, 24 May 2024 16:26:40 -0500 Subject: [PATCH] Add release workflow using GoReleaser --- .github/workflows/release.yaml | 59 +++++++++++++++++++ .goreleaser.yaml | 103 +++++++++++++++++++++++++++++++++ goreleaser.Dockerfile | 9 +++ 3 files changed, 171 insertions(+) create mode 100644 .github/workflows/release.yaml create mode 100644 .goreleaser.yaml create mode 100644 goreleaser.Dockerfile diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..2bd4426 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,59 @@ +name: Create release + +permissions: + contents: write + packages: write + +on: + # Only run the workflow when a tag that starts with "v" (e.g. "v1.2.3") is pushed. + push: + tags: + - 'v*' + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout the target Git reference + # https://github.com/actions/checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Log in to the GitHub Packages registry + # https://github.com/docker/login-action + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Log in to Docker Hub + env: + dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }} + dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }} + # Skip this step if credentials are not present. + if: ${{ env.dockerhub_username && env.dockerhub_token }} + # https://github.com/docker/login-action + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Set up Golang + # https://github.com/actions/setup-go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: Set up Docker buildx + # https://github.com/docker/setup-buildx-action + uses: docker/setup-buildx-action@v3 + + - name: Run GoReleaser + # https://github.com/goreleaser/goreleaser-action + uses: goreleaser/goreleaser-action@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + args: release diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..578cf62 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,103 @@ +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# .goreleaser.yaml +# ref: https://goreleaser.com/customization/ + +project_name: wfg/glance + +builds: + - binary: glance + env: + - CGO_ENABLED=0 + goos: + - darwin + - freebsd + - linux + - openbsd + - windows + +archives: + # Defaults to .tar.gz; override Windows to .zip. + - format_overrides: + - goos: windows + format: zip + +dockers: + # Build linux/amd64 image + - use: buildx + goarch: amd64 + dockerfile: goreleaser.Dockerfile + image_templates: + # - "{{ .ProjectName }}:{{ .Version }}-amd64" + - ghcr.io/{{ .ProjectName }}:{{ .Version }}-amd64 + build_flag_templates: + - --platform=linux/amd64 + + # Build linux/arm64/v7 image + - use: buildx + goarch: arm64 + dockerfile: goreleaser.Dockerfile + image_templates: + # - "{{ .ProjectName }}:{{ .Version }}-arm64v7" + - ghcr.io/{{ .ProjectName }}:{{ .Version }}-arm64v7 + build_flag_templates: + - --platform=linux/arm64/v7 + + # Build linux/arm64 image + - use: buildx + goarch: arm64 + dockerfile: goreleaser.Dockerfile + image_templates: + # - "{{ .ProjectName }}:{{ .Version }}-arm64" + - ghcr.io/{{ .ProjectName }}:{{ .Version }}-arm64 + build_flag_templates: + - --platform=linux/arm64 + + +docker_manifests: + # Bundle images into a single multi-arch image + + # glanceapp/glance:${tag} + # Creates tags for "v1.2.3", "v1.2", "v1", and latest + # - name_template: "{{ .ProjectName }}:v{{ .Major }}.{{ .Minor }}.{{ .Patch }}" + # image_templates: + # - "{{ .ProjectName }}:{{ .Version }}-amd64" + # - "{{ .ProjectName }}:{{ .Version }}-arm64v7" + # - "{{ .ProjectName }}:{{ .Version }}-arm64" + # - name_template: {{ .ProjectName }}:v{{ .Major }}.{{ .Minor }} + # image_templates: + # - "{{ .ProjectName }}:{{ .Version }}-amd64" + # - "{{ .ProjectName }}:{{ .Version }}-arm64v7" + # - "{{ .ProjectName }}:{{ .Version }}-arm64" + # - name_template: {{ .ProjectName }}:v{{ .Major }} + # image_templates: + # - "{{ .ProjectName }}:{{ .Version }}-amd64" + # - "{{ .ProjectName }}:{{ .Version }}-arm64v7" + # - "{{ .ProjectName }}:{{ .Version }}-arm64" + # - name_template: {{ .ProjectName }}:latest + # image_templates: + # - "{{ .ProjectName }}:{{ .Version }}-amd64" + # - "{{ .ProjectName }}:{{ .Version }}-arm64v7" + # - "{{ .ProjectName }}:{{ .Version }}-arm64" + + # ghcr.io/glanceapp/glance + # Creates tags for "v1.2.3", "v1.2", "v1", and latest + - name_template: ghcr.io/{{ .ProjectName }}:v{{ .Major }}.{{ .Minor }}.{{ .Patch }} + image_templates: + - ghcr.io/{{ .ProjectName }}:{{ .Version }}-amd64 + - ghcr.io/{{ .ProjectName }}:{{ .Version }}-arm64v7 + - ghcr.io/{{ .ProjectName }}:{{ .Version }}-arm64 + - name_template: ghcr.io/{{ .ProjectName }}:v{{ .Major }}.{{ .Minor }} + image_templates: + - ghcr.io/{{ .ProjectName }}:{{ .Version }}-amd64 + - ghcr.io/{{ .ProjectName }}:{{ .Version }}-arm64v7 + - ghcr.io/{{ .ProjectName }}:{{ .Version }}-arm64 + - name_template: ghcr.io/{{ .ProjectName }}:v{{ .Major }} + image_templates: + - ghcr.io/{{ .ProjectName }}:{{ .Version }}-amd64 + - ghcr.io/{{ .ProjectName }}:{{ .Version }}-arm64v7 + - ghcr.io/{{ .ProjectName }}:{{ .Version }}-arm64 + - name_template: ghcr.io/{{ .ProjectName }}:latest + image_templates: + - ghcr.io/{{ .ProjectName }}:{{ .Version }}-amd64 + - ghcr.io/{{ .ProjectName }}:{{ .Version }}-arm64v7 + - ghcr.io/{{ .ProjectName }}:{{ .Version }}-arm64 diff --git a/goreleaser.Dockerfile b/goreleaser.Dockerfile new file mode 100644 index 0000000..e22951e --- /dev/null +++ b/goreleaser.Dockerfile @@ -0,0 +1,9 @@ +FROM alpine:3.20 + +WORKDIR /app + +# This binary is an artifact from goreleaser. +COPY glance . +ENTRYPOINT ["/app/glance"] + +EXPOSE 8080/tcp