mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-26 08:13:09 -06:00
Build against musl in docker
This commit is contained in:
parent
cecdec2dec
commit
2e473d83af
|
|
@ -1,3 +1,3 @@
|
||||||
bin
|
bin
|
||||||
*.wasm
|
*.wasm
|
||||||
.git
|
.git
|
||||||
|
|
|
||||||
13
.github/workflows/Dockerfile.builder
vendored
Normal file
13
.github/workflows/Dockerfile.builder
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
FROM docker.io/golang:alpine AS builder
|
||||||
|
ARG GOARCH=amd64
|
||||||
|
|
||||||
|
RUN apk --update --no-cache add bash build-base
|
||||||
|
|
||||||
|
WORKDIR /build
|
||||||
|
|
||||||
|
COPY . /build
|
||||||
|
|
||||||
|
RUN bash /build/.github/workflows/get-compiler.sh pkgs
|
||||||
|
|
||||||
|
# Build!
|
||||||
|
RUN CC="$(/build/.github/workflows/get-compiler.sh ccomp)" bash /build/build.sh
|
||||||
7
.github/workflows/Dockerfile.copyin
vendored
7
.github/workflows/Dockerfile.copyin
vendored
|
|
@ -1,11 +1,12 @@
|
||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
|
|
||||||
ARG DENDRITE_BINARY=
|
ARG DENDRITE_BINARY=
|
||||||
ENV DENDRITE_BINARY=/usr/bin/${DENDRITE_BINARY}
|
ARG BIN_DIRECTORY=
|
||||||
|
ENV DENDRITE_BINARY=${DENDRITE_BINARY}
|
||||||
|
|
||||||
COPY ./bin/* /usr/bin
|
COPY --from=builder /build/bin/* /usr/bin
|
||||||
|
|
||||||
VOLUME /etc/dendrite
|
VOLUME /etc/dendrite
|
||||||
WORKDIR /etc/dendrite
|
WORKDIR /etc/dendrite
|
||||||
|
|
||||||
ENTRYPOINT ["${DENDRITE_BINARY}"]
|
ENTRYPOINT "/usr/bin/${DENDRITE_BINARY}"
|
||||||
|
|
|
||||||
50
.github/workflows/cross-compiling-docker.yml
vendored
50
.github/workflows/cross-compiling-docker.yml
vendored
|
|
@ -13,20 +13,29 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-go@v2
|
- uses: docker/setup-buildx-action@v1
|
||||||
- name: install (cross) compiler
|
- name: build dendrite in Docker
|
||||||
run: sudo apt install $(./.github/workflows/get-compiler.sh pkgs)
|
uses: docker/build-push-action@v2
|
||||||
- name: set CC env var
|
|
||||||
run: echo "CC=$(./.github/workflows/get-compiler.sh ccomp)" >> $GITHUB_ENV # https://stackoverflow.com/a/57969570/3551604
|
|
||||||
- run: go env
|
|
||||||
- run: ./build.sh
|
|
||||||
- name: upload build artifacts
|
|
||||||
uses: actions/upload-artifact@v2
|
|
||||||
with:
|
with:
|
||||||
name: bin-${{ matrix.target }}
|
context: .
|
||||||
path: ./bin
|
file: ./.github/workflows/Dockerfile.builder
|
||||||
|
load: true # load into local image store
|
||||||
|
tag: dendrite-builder:${{ matrix.target }}
|
||||||
|
- name: copy built files out of docker
|
||||||
|
run: docker -v "$(pwd)/bin:/build/bin-out" builder:${{ matrix.target }} "/bin/sh" "-c" "cp -a /build/bin/* /build/bin-out"
|
||||||
|
- uses: actions/upload-artifact@v2
|
||||||
|
with:
|
||||||
|
name: bin-${{ matrix.target }}
|
||||||
|
path: ./bin
|
||||||
build-monolith:
|
build-monolith:
|
||||||
needs: [compile]
|
needs: [compile]
|
||||||
|
local-registry:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
services:
|
||||||
|
registry:
|
||||||
|
image: registry:2
|
||||||
|
ports:
|
||||||
|
- 5000:5000
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
target: [amd64, arm64, arm]
|
target: [amd64, arm64, arm]
|
||||||
|
|
@ -40,17 +49,14 @@ jobs:
|
||||||
name: bin-${{ matrix.target }}
|
name: bin-${{ matrix.target }}
|
||||||
# - run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
# - run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
||||||
- run: echo "DOCKER_TARGET=$(./.github/workflows/get-compiler.sh docker)" >> $GITHUB_ENV
|
- run: echo "DOCKER_TARGET=$(./.github/workflows/get-compiler.sh docker)" >> $GITHUB_ENV
|
||||||
# For building docker images, QEMU and buildx is still easier than anything to do with docker manifest editing
|
- uses: docker/setup-qemu-action@v1
|
||||||
- name: Set up QEMU
|
- uses: docker/setup-buildx-action@v1
|
||||||
uses: docker/setup-qemu-action@v1
|
with:
|
||||||
- name: Set up Docker Buildx
|
driver-opts: network=host
|
||||||
uses: docker/setup-buildx-action@v1
|
- uses: docker/build-push-action@v2
|
||||||
- name: Build image
|
|
||||||
uses: docker/build-push-action@v2
|
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: ./.github/workflows/Dockerfile.copyin
|
file: ./.github/workflows/Dockerfile.copyin
|
||||||
platforms: ${{ env.PLATFORMS }}
|
platforms: ${{ DOCKER_TARGET }}
|
||||||
push: false
|
push: true
|
||||||
tags: |
|
tags: localhost:5000/matrixdotorg/dendrite-monolith:latest
|
||||||
${{ env.DOCKER_NAMESPACE }}/dendrite-monolith:latest
|
|
||||||
|
|
|
||||||
29
.github/workflows/get-compiler.sh
vendored
29
.github/workflows/get-compiler.sh
vendored
|
|
@ -1,5 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -eu
|
set -exu
|
||||||
|
|
||||||
|
MUSLCC_BASE="https://more.musl.cc/x86_64-linux-musl"
|
||||||
|
|
||||||
# Given a GOARCH target, return what Docker calls that target.
|
# Given a GOARCH target, return what Docker calls that target.
|
||||||
function get_docker() {
|
function get_docker() {
|
||||||
|
|
@ -23,38 +25,39 @@ function get_docker() {
|
||||||
function get_compiler() {
|
function get_compiler() {
|
||||||
case "$GOARCH" in
|
case "$GOARCH" in
|
||||||
"amd64")
|
"amd64")
|
||||||
echo "x86_64-linux-gnu-gcc"
|
echo "gcc"
|
||||||
;;
|
;;
|
||||||
"arm64")
|
"arm64")
|
||||||
echo "aarch64-linux-gnu-gcc"
|
echo "./aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc"
|
||||||
;;
|
;;
|
||||||
"arm")
|
"arm")
|
||||||
echo "arm-linux-gnueabihf-gcc"
|
echo "./arm-linux-musleabi-cross/bin/arm-linux-musleabi-gcc"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "gcc" # Send us a pull request if RISC-V ever takes off
|
exit 1 # Send us a pull request if RISC-V ever takes off
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
# Given a GOARCH target, return a list of Ubuntu packages needed to compile for that target.
|
function download_musl() {
|
||||||
function get_pkgs() {
|
|
||||||
case "$GOARCH" in
|
case "$GOARCH" in
|
||||||
"arm64")
|
"arm64")
|
||||||
echo "gcc-aarch64-linux-gnu libc6-dev-arm64-cross"
|
curl "${MUSLCC_BASE}/aarch64-linux-musl-cross.tgz" -o musl.tgz
|
||||||
|
tar xzf musl.tgz
|
||||||
;;
|
;;
|
||||||
"arm")
|
"arm")
|
||||||
echo "gcc-arm-linux-gnueabihf libc6-dev-armhf-cross"
|
curl "${MUSLCC_BASE}/arm-linux-musleabi-cross.tgz" -o musl.tgz
|
||||||
|
tar xzf musl.tgz
|
||||||
;;
|
;;
|
||||||
"amd64" | *)
|
"amd64")
|
||||||
# We (currently) don't need to install more packages on amd64.
|
echo "nothing to do"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
"pkgs")
|
"pkgs")
|
||||||
get_pkgs
|
download_musl
|
||||||
;;
|
;;
|
||||||
"ccomp")
|
"ccomp")
|
||||||
get_compiler
|
get_compiler
|
||||||
|
|
@ -65,4 +68,4 @@ case "$1" in
|
||||||
*)
|
*)
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue