mirror of
1
Fork 0

[packaging] Use buildx for multi-arch Docker builds (#413)

* update drone to create latest manifest

* add .dockerignore file

* use buildx for multi-arch builds
see https://docs.docker.com/buildx/working-with-buildx/

* don't use RUN commands in Dockerfile
this was breaking multi-arch builds
This commit is contained in:
tobi 2022-02-27 13:03:37 +01:00 committed by GitHub
parent 64d9a34c65
commit 6b634de6b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 59 additions and 30 deletions

9
.dockerignore Normal file
View File

@ -0,0 +1,9 @@
.github
cmd
docs
example
internal
scripts
test
testrig
vendor

View File

@ -57,7 +57,12 @@ steps:
- git fetch --tags - git fetch --tags
- /go/dockerlogin.sh - /go/dockerlogin.sh
- goreleaser release --rm-dist --snapshot - goreleaser release --rm-dist --snapshot
- docker push superseriousbusiness/gotosocial:latest - docker push superseriousbusiness/gotosocial:latest-armv6 &&
- docker push superseriousbusiness/gotosocial:latest-armv7
- docker push superseriousbusiness/gotosocial:latest-arm64v8
- docker push superseriousbusiness/gotosocial:latest-amd64
- docker manifest create superseriousbusiness/gotosocial:latest superseriousbusiness/gotosocial:latest-armv6 superseriousbusiness/gotosocial:latest-armv7 superseriousbusiness/gotosocial:latest-amd64 superseriousbusiness/gotosocial:latest-arm64v8
- docker manifest push superseriousbusiness/gotosocial:latest
when: when:
event: event:
include: include:
@ -144,6 +149,6 @@ steps:
--- ---
kind: signature kind: signature
hmac: 0487be0a2c9224c20cf067f94b3a458227e8b5465198b2245266d17156355b98 hmac: ea1a9c8fc0a872f43146651caeae4f724ca6a45c780456af5a1cbd093d9c51c5
... ...

View File

@ -39,6 +39,9 @@ builds:
- amd64 - amd64
- arm - arm
- arm64 - arm64
goarm:
- 6
- 7
ignore: ignore:
# build freebsd only for amd64 # build freebsd only for amd64
- goos: freebsd - goos: freebsd
@ -51,13 +54,14 @@ builds:
dockers: dockers:
# https://goreleaser.com/customization/docker/ # https://goreleaser.com/customization/docker/
- -
use: buildx
goos: linux goos: linux
goarch: amd64 goarch: amd64
image_templates: image_templates:
# - "superseriousbusiness/{{ .ProjectName }}:latest"
- "superseriousbusiness/{{ .ProjectName }}:{{ .Version }}-amd64" - "superseriousbusiness/{{ .ProjectName }}:{{ .Version }}-amd64"
- "superseriousbusiness/{{ .ProjectName }}:latest-amd64"
build_flag_templates: build_flag_templates:
- --platform=linux/amd64 - "--platform=linux/amd64"
- "--label=org.opencontainers.image.created={{.Date}}" - "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}" - "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}" - "--label=org.opencontainers.image.revision={{.FullCommit}}"
@ -65,13 +69,14 @@ dockers:
extra_files: extra_files:
- web - web
- -
use: buildx
goos: linux goos: linux
goarch: arm64 goarch: arm64
image_templates: image_templates:
# - "superseriousbusiness/{{ .ProjectName }}:latest"
- "superseriousbusiness/{{ .ProjectName }}:{{ .Version }}-arm64v8" - "superseriousbusiness/{{ .ProjectName }}:{{ .Version }}-arm64v8"
- "superseriousbusiness/{{ .ProjectName }}:latest-arm64v8"
build_flag_templates: build_flag_templates:
- --platform=linux/arm64/v8 - "--platform=linux/arm64/v8"
- "--label=org.opencontainers.image.created={{.Date}}" - "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}" - "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}" - "--label=org.opencontainers.image.revision={{.FullCommit}}"
@ -79,13 +84,31 @@ dockers:
extra_files: extra_files:
- web - web
- -
use: buildx
goos: linux goos: linux
goarch: arm goarch: arm
goarm: 6
image_templates: image_templates:
# - "superseriousbusiness/{{ .ProjectName }}:latest" - "superseriousbusiness/{{ .ProjectName }}:{{ .Version }}-armv6"
- "superseriousbusiness/{{ .ProjectName }}:{{ .Version }}-armv7" - "superseriousbusiness/{{ .ProjectName }}:latest-armv6"
build_flag_templates: build_flag_templates:
- --platform=linux/arm/v7 - "--platform=linux/arm/v6"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
extra_files:
- web
-
use: buildx
goos: linux
goarch: arm
goarm: 7
image_templates:
- "superseriousbusiness/{{ .ProjectName }}:{{ .Version }}-armv7"
- "superseriousbusiness/{{ .ProjectName }}:latest-armv7"
build_flag_templates:
- "--platform=linux/arm/v7"
- "--label=org.opencontainers.image.created={{.Date}}" - "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}" - "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}" - "--label=org.opencontainers.image.revision={{.FullCommit}}"
@ -97,12 +120,14 @@ docker_manifests:
image_templates: image_templates:
- superseriousbusiness/{{ .ProjectName }}:{{ .Version }}-amd64 - superseriousbusiness/{{ .ProjectName }}:{{ .Version }}-amd64
- superseriousbusiness/{{ .ProjectName }}:{{ .Version }}-arm64v8 - superseriousbusiness/{{ .ProjectName }}:{{ .Version }}-arm64v8
- superseriousbusiness/{{ .ProjectName }}:{{ .Version }}-armv6
- superseriousbusiness/{{ .ProjectName }}:{{ .Version }}-armv7 - superseriousbusiness/{{ .ProjectName }}:{{ .Version }}-armv7
- name_template: superseriousbusiness/{{ .ProjectName }}:latest - name_template: superseriousbusiness/{{ .ProjectName }}:latest
image_templates: image_templates:
- superseriousbusiness/{{ .ProjectName }}:{{ .Version }}-amd64 - superseriousbusiness/{{ .ProjectName }}:latest-amd64
- superseriousbusiness/{{ .ProjectName }}:{{ .Version }}-arm64v8 - superseriousbusiness/{{ .ProjectName }}:latest-arm64v8
- superseriousbusiness/{{ .ProjectName }}:{{ .Version }}-armv7 - superseriousbusiness/{{ .ProjectName }}:latest-armv6
- superseriousbusiness/{{ .ProjectName }}:latest-armv7
archives: archives:
# https://goreleaser.com/customization/archive/ # https://goreleaser.com/customization/archive/
- -

View File

@ -1,5 +1,7 @@
# syntax=docker/dockerfile:1.3
# bundle the admin webapp # bundle the admin webapp
FROM node:17.6.0-alpine3.15 AS admin_builder FROM --platform=${BUILDPLATFORM} node:17.6.0-alpine3.15 AS admin_builder
RUN apk update && apk upgrade --no-cache RUN apk update && apk upgrade --no-cache
RUN apk add git RUN apk add git
@ -9,28 +11,16 @@ WORKDIR /gotosocial-admin
RUN npm install RUN npm install
RUN node index.js RUN node index.js
FROM alpine:3.15.0 AS executor FROM --platform=${TARGETPLATFORM} alpine:3.15.0 AS executor
RUN apk update && apk upgrade --no-cache
# copy over the binary from the first stage # copy over the binary from the first stage
RUN mkdir -p /gotosocial/storage COPY --chown=1000:1000 gotosocial /gotosocial/gotosocial
COPY gotosocial /gotosocial/gotosocial
# copy over the web directory with templates etc # copy over the web directory with templates etc
COPY web /gotosocial/web COPY --chown=1000:1000 web /gotosocial/web
# copy over the admin directory # copy over the admin directory
COPY --from=admin_builder /gotosocial-admin/public /gotosocial/web/assets/admin COPY --chown=1000:1000 --from=admin_builder /gotosocial-admin/public /gotosocial/web/assets/admin
# make the gotosocial group and user WORKDIR "/gotosocial"
RUN addgroup -g 1000 gotosocial
RUN adduser -HD -u 1000 -G gotosocial gotosocial
# give ownership of the gotosocial dir to the new user
RUN chown -R gotosocial gotosocial /gotosocial
# become the user
USER gotosocial
WORKDIR /gotosocial
ENTRYPOINT [ "/gotosocial/gotosocial", "server", "start" ] ENTRYPOINT [ "/gotosocial/gotosocial", "server", "start" ]