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
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
|
||||
|
||||
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
|
||||
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
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-go@v2
|
||||
- name: install (cross) compiler
|
||||
run: sudo apt install $(./.github/workflows/get-compiler.sh pkgs)
|
||||
- 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
|
||||
- uses: docker/setup-buildx-action@v1
|
||||
- name: build dendrite in Docker
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
name: bin-${{ matrix.target }}
|
||||
path: ./bin
|
||||
context: .
|
||||
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:
|
||||
needs: [compile]
|
||||
local-registry:
|
||||
runs-on: ubuntu-latest
|
||||
services:
|
||||
registry:
|
||||
image: registry:2
|
||||
ports:
|
||||
- 5000:5000
|
||||
strategy:
|
||||
matrix:
|
||||
target: [amd64, arm64, arm]
|
||||
|
|
@ -40,17 +49,14 @@ jobs:
|
|||
name: bin-${{ matrix.target }}
|
||||
# - run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $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
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v1
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
- name: Build image
|
||||
uses: docker/build-push-action@v2
|
||||
- uses: docker/setup-qemu-action@v1
|
||||
- uses: docker/setup-buildx-action@v1
|
||||
with:
|
||||
driver-opts: network=host
|
||||
- uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: .
|
||||
file: ./.github/workflows/Dockerfile.copyin
|
||||
platforms: ${{ env.PLATFORMS }}
|
||||
push: false
|
||||
tags: |
|
||||
${{ env.DOCKER_NAMESPACE }}/dendrite-monolith:latest
|
||||
platforms: ${{ DOCKER_TARGET }}
|
||||
push: true
|
||||
tags: localhost:5000/matrixdotorg/dendrite-monolith:latest
|
||||
|
|
|
|||
27
.github/workflows/get-compiler.sh
vendored
27
.github/workflows/get-compiler.sh
vendored
|
|
@ -1,5 +1,7 @@
|
|||
#!/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.
|
||||
function get_docker() {
|
||||
|
|
@ -23,38 +25,39 @@ function get_docker() {
|
|||
function get_compiler() {
|
||||
case "$GOARCH" in
|
||||
"amd64")
|
||||
echo "x86_64-linux-gnu-gcc"
|
||||
echo "gcc"
|
||||
;;
|
||||
"arm64")
|
||||
echo "aarch64-linux-gnu-gcc"
|
||||
echo "./aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc"
|
||||
;;
|
||||
"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
|
||||
}
|
||||
|
||||
# Given a GOARCH target, return a list of Ubuntu packages needed to compile for that target.
|
||||
function get_pkgs() {
|
||||
function download_musl() {
|
||||
case "$GOARCH" in
|
||||
"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")
|
||||
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" | *)
|
||||
# We (currently) don't need to install more packages on amd64.
|
||||
"amd64")
|
||||
echo "nothing to do"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
"pkgs")
|
||||
get_pkgs
|
||||
download_musl
|
||||
;;
|
||||
"ccomp")
|
||||
get_compiler
|
||||
|
|
|
|||
Loading…
Reference in a new issue