From ba0f92393a3338140c771cf7dee9efa80e675bed Mon Sep 17 00:00:00 2001 From: Jacob Weinstock Date: Tue, 4 Jan 2022 19:34:59 -0700 Subject: [PATCH] Enable container image building and pushing: This uses goreleaser to build and push container images to quay.io for multiple architectures. Signed-off-by: Jacob Weinstock --- .github/workflows/publish.yaml | 29 +++++++++++++ .gitignore | 2 + .goreleaser.yaml | 77 ++++++++++++++++++++++++++++++++++ Dockerfile | 4 +- Dockerfile.goreleaser | 8 ++++ 5 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/publish.yaml create mode 100644 .goreleaser.yaml create mode 100644 Dockerfile.goreleaser diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..0bff645 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,29 @@ +name: Publish Release +on: + push: + tags: + - "*" +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.17.5 + - name: Login to quay.io + if: github.event_name != 'pull_request' + uses: docker/login-action@v1 + with: + registry: quay.io + username: ${{ secrets.QUAY_USERNAME }} + password: ${{ secrets.QUAY_PASSWORD }} + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: release --rm-dist diff --git a/.gitignore b/.gitignore index 7cbfd98..2a246d6 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,5 @@ ipxe-*.tar.gz # added by lint-install out/ + +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..2538cb9 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,77 @@ +before: + hooks: + - go mod tidy +builds: + - env: + - CGO_ENABLED=0 + flags: -trimpath + ldflags: '-s -w -extldflags "-static"' + main: ./cmd/ + goos: + - linux + - darwin + goarch: + - amd64 + - arm64 + - arm +archives: + - replacements: + darwin: Darwin + linux: Linux + amd64: x86_64 +checksum: + name_template: "checksums.txt" +snapshot: + name_template: "{{ incpatch .Version }}-next" +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" +dockers: + - image_templates: + - "quay.io/tinkerbell/ipxedust:{{ .Version }}-amd64" + use: buildx + dockerfile: Dockerfile.goreleaser + 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}}" + - "--platform=linux/amd64" + - image_templates: + - "quay.io/tinkerbell/ipxedust:{{ .Version }}-arm64" + use: buildx + goarch: arm64 + dockerfile: Dockerfile.goreleaser + 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}}" + - "--platform=linux/arm64" + - image_templates: + - "quay.io/tinkerbell/ipxedust:{{ .Version }}-arm" + use: buildx + goarch: arm + goarm: "6" + dockerfile: Dockerfile.goreleaser + 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}}" + - "--platform=linux/arm/v6" +docker_manifests: + - name_template: quay.io/tinkerbell/ipxedust:{{ .Version }} + image_templates: + - quay.io/tinkerbell/ipxedust:{{ .Version }}-amd64 + - quay.io/tinkerbell/ipxedust:{{ .Version }}-arm64 + - quay.io/tinkerbell/ipxedust:{{ .Version }}-arm diff --git a/Dockerfile b/Dockerfile index 4e57a1c..902424e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,9 +9,9 @@ RUN CGO_ENABLED=0 make build FROM scratch -COPY --from=builder /code/bin/ipxedust-linux /ipxedust-linux +COPY --from=builder /code/bin/ipxedust-linux /ipxedust EXPOSE 69/udp EXPOSE 8080/tcp ENV IPXE_TFTP_SINGLE_PORT=TRUE -ENTRYPOINT ["/ipxedust-linux"] \ No newline at end of file +ENTRYPOINT ["/ipxedust"] diff --git a/Dockerfile.goreleaser b/Dockerfile.goreleaser new file mode 100644 index 0000000..89e0893 --- /dev/null +++ b/Dockerfile.goreleaser @@ -0,0 +1,8 @@ +FROM scratch + +COPY ipxedust /ipxedust +EXPOSE 69/udp +EXPOSE 8080/tcp +ENV IPXE_TFTP_SINGLE_PORT=TRUE + +ENTRYPOINT ["/ipxedust"]