Skip to content

Commit

Permalink
[packaging] Use buildx for multi-arch Docker builds (#413)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
tsmethurst committed Feb 27, 2022
1 parent 64d9a34 commit 6b634de
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 29 deletions.
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.github
cmd
docs
example
internal
scripts
test
testrig
vendor
9 changes: 7 additions & 2 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ steps:
- git fetch --tags
- /go/dockerlogin.sh
- 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:
event:
include:
Expand Down Expand Up @@ -144,6 +149,6 @@ steps:

---
kind: signature
hmac: 0487be0a2c9224c20cf067f94b3a458227e8b5465198b2245266d17156355b98
hmac: ea1a9c8fc0a872f43146651caeae4f724ca6a45c780456af5a1cbd093d9c51c5

...
43 changes: 34 additions & 9 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ builds:
- amd64
- arm
- arm64
goarm:
- 6
- 7
ignore:
# build freebsd only for amd64
- goos: freebsd
Expand All @@ -51,41 +54,61 @@ builds:
dockers:
# https://goreleaser.com/customization/docker/
-
use: buildx
goos: linux
goarch: amd64
image_templates:
# - "superseriousbusiness/{{ .ProjectName }}:latest"
- "superseriousbusiness/{{ .ProjectName }}:{{ .Version }}-amd64"
- "superseriousbusiness/{{ .ProjectName }}:latest-amd64"
build_flag_templates:
- --platform=linux/amd64
- "--platform=linux/amd64"
- "--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: arm64
image_templates:
# - "superseriousbusiness/{{ .ProjectName }}:latest"
- "superseriousbusiness/{{ .ProjectName }}:{{ .Version }}-arm64v8"
- "superseriousbusiness/{{ .ProjectName }}:latest-arm64v8"
build_flag_templates:
- --platform=linux/arm64/v8
- "--platform=linux/arm64/v8"
- "--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: 6
image_templates:
- "superseriousbusiness/{{ .ProjectName }}:{{ .Version }}-armv6"
- "superseriousbusiness/{{ .ProjectName }}:latest-armv6"
build_flag_templates:
- "--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 }}:latest"
- "superseriousbusiness/{{ .ProjectName }}:{{ .Version }}-armv7"
- "superseriousbusiness/{{ .ProjectName }}:latest-armv7"
build_flag_templates:
- --platform=linux/arm/v7
- "--platform=linux/arm/v7"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
Expand All @@ -97,12 +120,14 @@ docker_manifests:
image_templates:
- superseriousbusiness/{{ .ProjectName }}:{{ .Version }}-amd64
- superseriousbusiness/{{ .ProjectName }}:{{ .Version }}-arm64v8
- superseriousbusiness/{{ .ProjectName }}:{{ .Version }}-armv6
- superseriousbusiness/{{ .ProjectName }}:{{ .Version }}-armv7
- name_template: superseriousbusiness/{{ .ProjectName }}:latest
image_templates:
- superseriousbusiness/{{ .ProjectName }}:{{ .Version }}-amd64
- superseriousbusiness/{{ .ProjectName }}:{{ .Version }}-arm64v8
- superseriousbusiness/{{ .ProjectName }}:{{ .Version }}-armv7
- superseriousbusiness/{{ .ProjectName }}:latest-amd64
- superseriousbusiness/{{ .ProjectName }}:latest-arm64v8
- superseriousbusiness/{{ .ProjectName }}:latest-armv6
- superseriousbusiness/{{ .ProjectName }}:latest-armv7
archives:
# https://goreleaser.com/customization/archive/
-
Expand Down
26 changes: 8 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# syntax=docker/dockerfile:1.3

# 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 add git

Expand All @@ -9,28 +11,16 @@ WORKDIR /gotosocial-admin
RUN npm install
RUN node index.js

FROM alpine:3.15.0 AS executor
RUN apk update && apk upgrade --no-cache
FROM --platform=${TARGETPLATFORM} alpine:3.15.0 AS executor

# copy over the binary from the first stage
RUN mkdir -p /gotosocial/storage
COPY gotosocial /gotosocial/gotosocial
COPY --chown=1000:1000 gotosocial /gotosocial/gotosocial

# 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 --from=admin_builder /gotosocial-admin/public /gotosocial/web/assets/admin

# make the gotosocial group and user
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
COPY --chown=1000:1000 --from=admin_builder /gotosocial-admin/public /gotosocial/web/assets/admin

WORKDIR /gotosocial
WORKDIR "/gotosocial"
ENTRYPOINT [ "/gotosocial/gotosocial", "server", "start" ]

0 comments on commit 6b634de

Please sign in to comment.