diff --git a/.dockerignore b/.dockerignore index 76547e9ee..2d437e932 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,3 @@ bin *.wasm -.git \ No newline at end of file +.git diff --git a/.github/workflows/Dockerfile.builder b/.github/workflows/Dockerfile.builder new file mode 100644 index 000000000..f4942b41d --- /dev/null +++ b/.github/workflows/Dockerfile.builder @@ -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 diff --git a/.github/workflows/Dockerfile.copyin b/.github/workflows/Dockerfile.copyin index 636d7338d..a89051cb7 100644 --- a/.github/workflows/Dockerfile.copyin +++ b/.github/workflows/Dockerfile.copyin @@ -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}"] \ No newline at end of file +ENTRYPOINT "/usr/bin/${DENDRITE_BINARY}" diff --git a/.github/workflows/cross-compiling-docker.yml b/.github/workflows/cross-compiling-docker.yml index a1e8cb4f8..b4f228dd6 100644 --- a/.github/workflows/cross-compiling-docker.yml +++ b/.github/workflows/cross-compiling-docker.yml @@ -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 diff --git a/.github/workflows/get-compiler.sh b/.github/workflows/get-compiler.sh index 8494517fd..b3ea2cd23 100755 --- a/.github/workflows/get-compiler.sh +++ b/.github/workflows/get-compiler.sh @@ -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 @@ -65,4 +68,4 @@ case "$1" in *) exit 1 ;; -esac \ No newline at end of file +esac