mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-16 18:43:10 -06:00
Multi-stage images without Cgo
This commit is contained in:
parent
0caaeb7d44
commit
96d1d96a01
45
.github/workflows/docker.yml
vendored
45
.github/workflows/docker.yml
vendored
|
|
@ -211,7 +211,7 @@ jobs:
|
|||
username: ${{ github.repository_owner }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Build main pinecone demo image
|
||||
- name: Build main Pinecone demo image
|
||||
if: github.ref_name == 'main'
|
||||
id: docker_build_demo_pinecone
|
||||
uses: docker/build-push-action@v3
|
||||
|
|
@ -226,7 +226,7 @@ jobs:
|
|||
${{ env.DOCKER_NAMESPACE }}/dendrite-demo-pinecone:${{ github.ref_name }}
|
||||
ghcr.io/${{ env.GHCR_NAMESPACE }}/dendrite-demo-pinecone:${{ github.ref_name }}
|
||||
|
||||
- name: Build release pinecone demo image
|
||||
- name: Build release Pinecone demo image
|
||||
if: github.event_name == 'release' # Only for GitHub releases
|
||||
id: docker_build_demo_pinecone_release
|
||||
uses: docker/build-push-action@v3
|
||||
|
|
@ -239,7 +239,40 @@ jobs:
|
|||
platforms: ${{ env.PLATFORMS }}
|
||||
push: true
|
||||
tags: |
|
||||
${{ env.DOCKER_NAMESPACE }}/dendrite-demo-pinecone:latest
|
||||
${{ env.DOCKER_NAMESPACE }}/dendrite-demo-pinecone:${{ env.RELEASE_VERSION }}
|
||||
ghcr.io/${{ env.GHCR_NAMESPACE }}/dendrite-demo-pinecone:latest
|
||||
ghcr.io/${{ env.GHCR_NAMESPACE }}/dendrite-demo-pinecone:${{ env.RELEASE_VERSION }}
|
||||
${{ env.DOCKER_NAMESPACE }}/dendrite-demo-yggdrasil:latest
|
||||
${{ env.DOCKER_NAMESPACE }}/dendrite-demo-yggdrasil:${{ env.RELEASE_VERSION }}
|
||||
ghcr.io/${{ env.GHCR_NAMESPACE }}/dendrite-demo-yggdrasil:latest
|
||||
ghcr.io/${{ env.GHCR_NAMESPACE }}/dendrite-demo-yggdrasil:${{ env.RELEASE_VERSION }}
|
||||
|
||||
- name: Build main Yggdrasil demo image
|
||||
if: github.ref_name == 'main'
|
||||
id: docker_build_demo_yggdrasil
|
||||
uses: docker/build-push-action@v3
|
||||
with:
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
context: .
|
||||
target: demo-yggdrasil
|
||||
platforms: ${{ env.PLATFORMS }}
|
||||
push: true
|
||||
tags: |
|
||||
${{ env.DOCKER_NAMESPACE }}/dendrite-demo-yggdrasil:${{ github.ref_name }}
|
||||
ghcr.io/${{ env.GHCR_NAMESPACE }}/dendrite-demo-yggdrasil:${{ github.ref_name }}
|
||||
|
||||
- name: Build release Yggdrasil demo image
|
||||
if: github.event_name == 'release' # Only for GitHub releases
|
||||
id: docker_build_demo_yggdrasil_release
|
||||
uses: docker/build-push-action@v3
|
||||
with:
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
context: .
|
||||
build-args: FLAGS="-X github.com/matrix-org/dendrite/internal.branch=${{ env.BRANCH }} -X github.com/matrix-org/dendrite/internal.build=${{ env.BUILD }}"
|
||||
target: demo-yggdrasil
|
||||
platforms: ${{ env.PLATFORMS }}
|
||||
push: true
|
||||
tags: |
|
||||
${{ env.DOCKER_NAMESPACE }}/dendrite-demo-yggdrasil:latest
|
||||
${{ env.DOCKER_NAMESPACE }}/dendrite-demo-yggdrasil:${{ env.RELEASE_VERSION }}
|
||||
ghcr.io/${{ env.GHCR_NAMESPACE }}/dendrite-demo-yggdrasil:latest
|
||||
ghcr.io/${{ env.GHCR_NAMESPACE }}/dendrite-demo-yggdrasil:${{ env.RELEASE_VERSION }}
|
||||
|
|
|
|||
33
Dockerfile
33
Dockerfile
|
|
@ -16,7 +16,11 @@ ARG TARGETARCH
|
|||
ARG FLAGS
|
||||
RUN --mount=target=. \
|
||||
--mount=type=cache,target=/root/.cache/go-build \
|
||||
sh ./build/docker/crossbuild.sh
|
||||
USERARCH=`go env GOARCH` \
|
||||
GOARCH="$TARGETARCH" \
|
||||
GOOS="linux" \
|
||||
CGO_ENABLED=$([ "$TARGETARCH" = "$USERARCH" ] && echo "1" || echo "0") \
|
||||
go build -v -ldflags="${FLAGS}" -trimpath -o /out/ ./cmd/...
|
||||
|
||||
#
|
||||
# The dendrite base image; mainly creates a user and switches to it
|
||||
|
|
@ -56,10 +60,10 @@ ENTRYPOINT ["/usr/bin/dendrite-monolith-server"]
|
|||
EXPOSE 8008 8448
|
||||
|
||||
#
|
||||
# Builds the P2P demo image and contains all required binaries
|
||||
# Builds the Pinecone P2P demo image and contains all required binaries
|
||||
#
|
||||
FROM dendrite-base AS demo-pinecone
|
||||
LABEL org.opencontainers.image.title="Dendrite (P2P Demo)"
|
||||
LABEL org.opencontainers.image.title="Dendrite (Pinecone P2P Demo)"
|
||||
|
||||
COPY --from=build /out/create-account /usr/bin/create-account
|
||||
COPY --from=build /out/generate-config /usr/bin/generate-config
|
||||
|
|
@ -72,14 +76,33 @@ WORKDIR /etc/dendrite
|
|||
ENTRYPOINT ["/usr/bin/dendrite-demo-pinecone"]
|
||||
EXPOSE 8008 8448
|
||||
|
||||
#
|
||||
# Builds the Yggdrasil P2P demo image and contains all required binaries
|
||||
#
|
||||
FROM dendrite-base AS demo-yggdrasil
|
||||
LABEL org.opencontainers.image.title="Dendrite (Yggdrasil P2P Demo)"
|
||||
|
||||
COPY --from=build /out/create-account /usr/bin/create-account
|
||||
COPY --from=build /out/generate-config /usr/bin/generate-config
|
||||
COPY --from=build /out/generate-keys /usr/bin/generate-keys
|
||||
COPY --from=build /out/dendrite-demo-yggdrasil /usr/bin/dendrite-demo-yggdrasil
|
||||
|
||||
VOLUME /etc/dendrite
|
||||
WORKDIR /etc/dendrite
|
||||
|
||||
ENTRYPOINT ["/usr/bin/dendrite-demo-yggdrasil"]
|
||||
EXPOSE 8008 8448
|
||||
|
||||
#
|
||||
# Builds the Complement image, used for integration tests
|
||||
#
|
||||
FROM base AS complement
|
||||
LABEL org.opencontainers.image.title="Dendrite (Complement)"
|
||||
RUN apk add --no-cache sqlite openssl ca-certificates
|
||||
COPY --from=build /out/* /usr/bin/
|
||||
RUN rm /usr/bin/dendrite-polylith-multi /usr/bin/dendrite-demo* /usr/bin/dendritejs-pinecone
|
||||
|
||||
COPY --from=build /out/generate-config /usr/bin/generate-config
|
||||
COPY --from=build /out/generate-keys /usr/bin/generate-keys
|
||||
COPY --from=build /out/dendrite-monolith-server /usr/bin/dendrite-monolith-server
|
||||
|
||||
WORKDIR /dendrite
|
||||
RUN /usr/bin/generate-keys --private-key matrix_key.pem && \
|
||||
|
|
|
|||
|
|
@ -1,25 +0,0 @@
|
|||
FROM docker.io/golang:1.19-alpine AS base
|
||||
|
||||
RUN apk --update --no-cache add bash build-base
|
||||
|
||||
WORKDIR /build
|
||||
|
||||
COPY . /build
|
||||
|
||||
RUN mkdir -p bin
|
||||
RUN go build -trimpath -o bin/ ./cmd/dendrite-demo-yggdrasil
|
||||
RUN go build -trimpath -o bin/ ./cmd/create-account
|
||||
RUN go build -trimpath -o bin/ ./cmd/generate-keys
|
||||
|
||||
FROM alpine:latest
|
||||
LABEL org.opencontainers.image.title="Dendrite (Yggdrasil demo)"
|
||||
LABEL org.opencontainers.image.description="Next-generation Matrix homeserver written in Go"
|
||||
LABEL org.opencontainers.image.source="https://github.com/matrix-org/dendrite"
|
||||
LABEL org.opencontainers.image.licenses="Apache-2.0"
|
||||
|
||||
COPY --from=base /build/bin/* /usr/bin/
|
||||
|
||||
VOLUME /etc/dendrite
|
||||
WORKDIR /etc/dendrite
|
||||
|
||||
ENTRYPOINT ["/usr/bin/dendrite-demo-yggdrasil"]
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
# In order to cross-compile with the multi-stage Docker builds, we need to
|
||||
# ensure that the suitable toolchain for cross-compiling is installed. Since
|
||||
# the images are Alpine-based, we will use musl. Download and install the
|
||||
# toolchain inside the build container.
|
||||
|
||||
USERARCH=`go env GOARCH`
|
||||
GOARCH="$TARGETARCH"
|
||||
GOOS="linux"
|
||||
|
||||
echo "Target arch: $TARGETARCH"
|
||||
echo "User arch: $USERARCH"
|
||||
|
||||
if [ "$TARGETARCH" != "$USERARCH" ]; then
|
||||
if [ "$USERARCH" != "amd64" ]; then
|
||||
echo "Cross-compiling only supported on amd64"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Cross compile"
|
||||
case $GOARCH in
|
||||
arm64)
|
||||
curl -s https://more.musl.cc/x86_64-linux-musl/aarch64-linux-musl-cross.tgz | tar xz --strip-components=1 -C /usr
|
||||
export CC=aarch64-linux-musl-gcc
|
||||
;;
|
||||
|
||||
amd64)
|
||||
curl -s https://more.musl.cc/x86_64-linux-musl/x86_64-linux-musl-cross.tgz | tar xz --strip-components=1 -C /usr
|
||||
export CC=x86_64-linux-musl-gcc
|
||||
;;
|
||||
|
||||
386)
|
||||
curl -s https://more.musl.cc/x86_64-linux-musl/i686-linux-musl-cross.tgz | tar xz --strip-components=1 -C /usr
|
||||
export CC=i686-linux-musl-gcc
|
||||
;;
|
||||
|
||||
arm)
|
||||
curl -s https://more.musl.cc/x86_64-linux-musl/armv7l-linux-musleabihf-cross.tgz | tar xz --strip-components=1 -C /usr
|
||||
export CC=armv7l-linux-musleabihf-gcc
|
||||
;;
|
||||
|
||||
s390x)
|
||||
curl -s https://more.musl.cc/x86_64-linux-musl/s390x-linux-musl-cross.tgz | tar xz --strip-components=1 -C /usr
|
||||
export CC=s390x-linux-musl-gcc
|
||||
;;
|
||||
|
||||
ppc64le)
|
||||
curl -s https://more.musl.cc/x86_64-linux-musl/powerpc64le-linux-musl-cross.tgz | tar xz --strip-components=1 -C /usr
|
||||
export CC=powerpc64le-linux-musl-gcc
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Unsupported GOARCH=${GOARCH}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
else
|
||||
echo "Native compile"
|
||||
fi
|
||||
|
||||
# Output the go environment just in case it is useful for debugging.
|
||||
go env
|
||||
|
||||
# Build Dendrite and tools, statically linking them.
|
||||
CGO_ENABLED=1 go build -v -ldflags="-linkmode external -extldflags -static ${FLAGS}" -trimpath -o /out/ ./cmd/...
|
||||
Loading…
Reference in a new issue