diff --git a/.dockerignore b/.dockerignore index 89caab4..034e057 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,7 @@ docker .github -.goreleaser.yaml +flake.lock +flake.nix +sources +README.md +Makefile \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2cd1c32..a1770f6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,6 +5,8 @@ on: push: branches: - 'master' + tags: + - 'v*' pull_request: branches: - 'master' @@ -13,10 +15,19 @@ env: REGISTRY: ghcr.io # github.repository as / IMAGE_NAME: ${{ github.repository }} + REGISTRY_IMAGE: "ghcr.io/cottand/grimd" jobs: docker: runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + platform: + - linux/amd64 + - linux/arm/v6 + - linux/arm/v7 + - linux/arm64 steps: - name: Checkout uses: actions/checkout@v3 @@ -43,28 +54,81 @@ jobs: - name: Docker meta id: meta - uses: docker/metadata-action@v4 + uses: docker/metadata-action@v5 with: # list of Docker images to use as base name for tags - images: | - ghcr.io/cottand/grimd + images: ${{ env.REGISTRY_IMAGE }} tags: | - type=schedule - type=ref,event=branch - type=sha + type=sha,enable=false - - name: Build and push + - name: Build and push (by digest) uses: docker/build-push-action@v4 + id: build with: push: true context: . file: docker/slim.Dockerfile tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - platforms: linux/amd64, linux/arm64 + platforms: ${{ matrix.platform }} + outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true cache-from: type=gha cache-to: type=gha,mode=max + - name: Export digest + run: | + mkdir -p /tmp/digests + digest="${{ steps.build.outputs.digest }}" + touch "/tmp/digests/${digest#sha256:}" + - name: Upload digest + uses: actions/upload-artifact@v3 + with: + name: digests + path: /tmp/digests/* + if-no-files-found: error + retention-days: 1 + merge-docker: + runs-on: ubuntu-latest + needs: [docker] + steps: + - name: Download digests + uses: actions/download-artifact@v3 + with: + name: digests + path: /tmp/digests + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + # list of Docker images to use as base name for tags + images: ${{ env.REGISTRY_IMAGE }} + tags: | + type=schedule + # tag event + type=ref,event=tag + type=sha,event=tag + # pull request event + type=sha,event=pr + + + - name: Create manifest list and push + working-directory: /tmp/digests + run: | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ + $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) + - name: Inspect image + run: | + docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} - name: Summary run: | - echo "Published: \`${{ steps.meta.outputs.tags }}\`" >> $GITHUB_STEP_SUMMARY + echo "# Published \`${{ steps.meta.outputs.tags }}\`" >> $GITHUB_STEP_SUMMARY diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml deleted file mode 100644 index 33718a6..0000000 --- a/.github/workflows/release.yaml +++ /dev/null @@ -1,64 +0,0 @@ -name: Release - -on: - workflow_dispatch: - push: - branches: - - 'master' - tags: - - 'v*' -env: - # Use docker.io for Docker Hub if empty - REGISTRY: ghcr.io - # github.repository as / - IMAGE_NAME: ${{ github.repository }} - - -jobs: - release: - runs-on: ubuntu-latest - steps: - - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.21 - - - name: Cache Go modules - uses: actions/cache@v1 - with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - - name: Tests - run: | - go test -v ./... - # Login against a Docker registry except on PR - # https://github.com/docker/login-action - - name: Log into registry ${{ env.REGISTRY }} - if: github.event_name != 'pull_request' - uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v2 - if: success() && startsWith(github.ref, 'refs/tags/') - with: - version: latest - args: release --clean - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser.yaml b/.goreleaser.yaml deleted file mode 100644 index 0031f4d..0000000 --- a/.goreleaser.yaml +++ /dev/null @@ -1,52 +0,0 @@ -project_name: grimd -dockers: - - image_templates: - - "ghcr.io/cottand/grimd:latest-amd64" - - "ghcr.io/cottand/grimd:{{ .Tag }}-amd64" - dockerfile: docker/gorelease.Dockerfile - build_flag_templates: - - --pull - - --platform=linux/amd64 - - --label=org.opencontainers.image.title={{ .ProjectName }} - - --label=org.opencontainers.image.description={{ .ProjectName }} - - --label=org.opencontainers.image.url=https://github.com/cottand/grimd - - --label=org.opencontainers.image.source=https://github.com/cottand/grimd - - --label=org.opencontainers.image.version={{ .Version }} - - --label=org.opencontainers.image.created={{ .Date }} - - --label=org.opencontainers.image.revision={{ .FullCommit }} - - --label=org.opencontainers.image.licenses=MIT - use: buildx - - image_templates: - - "ghcr.io/cottand/grimd:latest-arm64" - - "ghcr.io/cottand/grimd:{{ .Tag }}-arm64" - dockerfile: docker/gorelease.Dockerfile - build_flag_templates: - - --pull - - --platform=linux/arm64 - - --label=org.opencontainers.image.title={{ .ProjectName }} - - --label=org.opencontainers.image.description={{ .ProjectName }} - - --label=org.opencontainers.image.url=https://github.com/cottand/grimd - - --label=org.opencontainers.image.source=https://github.com/cottand/grimd - - --label=org.opencontainers.image.version={{ .Version }} - - --label=org.opencontainers.image.created={{ .Date }} - - --label=org.opencontainers.image.revision={{ .FullCommit }} - - --label=org.opencontainers.image.licenses=MIT - use: buildx - goarch: arm64 -docker_manifests: - - name_template: 'ghcr.io/cottand/grimd:{{ .Tag }}' - image_templates: - - 'ghcr.io/cottand/grimd:{{ .Tag }}-amd64' - - 'ghcr.io/cottand/grimd:{{ .Tag }}-arm64' - - name_template: 'ghcr.io/cottand/grimd:latest' - image_templates: - - 'ghcr.io/cottand/grimd:{{ .Tag }}-amd64' - - 'ghcr.io/cottand/grimd:{{ .Tag }}-arm64' -builds: - - env: [CGO_ENABLED=0] - goos: - - linux - - darwin - goarch: - - amd64 - - arm64 diff --git a/docker/gorelease.Dockerfile b/docker/gorelease.Dockerfile deleted file mode 100644 index cc74ded..0000000 --- a/docker/gorelease.Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM alpine:3.16.0 as certs -RUN apk --update add ca-certificates - -FROM scratch -COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt -COPY grimd /usr/bin/grimd -EXPOSE 53/udp -EXPOSE 53/tcp -EXPOSE 8080/tcp -ENTRYPOINT ["/usr/bin/grimd"] \ No newline at end of file