From 284fe7f1a68fe2a40c974787eeb31c4b2e6d505a Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Mon, 19 Oct 2020 15:36:40 +0300 Subject: [PATCH] Build static executables with olm using gomuks-build-docker --- .gitlab-ci.yml | 44 ++++++++------------------------------------ Dockerfile.ci | 10 +++++----- 2 files changed, 13 insertions(+), 41 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 907d00d..ba94709 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,17 +4,15 @@ stages: - manifest .build: &build - image: golang:1-alpine stage: build cache: paths: - .cache before_script: - - apk add build-base olm-dev && apk policy olm-dev - mkdir -p .cache - export GOPATH="$CI_PROJECT_DIR/.cache" - export GOCACHE="$CI_PROJECT_DIR/.cache/build" - - export GO_LDFLAGS="-X main.Tag=$CI_COMMIT_TAG -X main.Commit=$CI_COMMIT_SHA -X 'main.BuildTime=`date '+%b %_d %Y, %H:%M:%S'`'" + - export GO_LDFLAGS="-linkmode external -extldflags -static -X main.Tag=$CI_COMMIT_TAG -X main.Commit=$CI_COMMIT_SHA -X 'main.BuildTime=`date '+%b %_d %Y, %H:%M:%S'`'" script: - go build -ldflags "$GO_LDFLAGS" -o mautrix-whatsapp artifacts: @@ -29,47 +27,21 @@ stages: - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY script: - docker pull $CI_REGISTRY_IMAGE:latest || true - - docker build --pull --cache-from $CI_REGISTRY_IMAGE:latest --build-arg TARGETARCH=$DOCKER_ARCH --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-$DOCKER_ARCH . --file Dockerfile.ci + - docker build --pull --cache-from $CI_REGISTRY_IMAGE:latest --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-$DOCKER_ARCH . --file Dockerfile.ci - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-$DOCKER_ARCH - docker rmi $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-$DOCKER_ARCH -build static: - image: golang:1-alpine - stage: build - tags: - - amd64 - cache: - paths: - - .cache - before_script: - - mkdir -p .cache - - export GOPATH="$CI_PROJECT_DIR/.cache" - - export GOCACHE="$CI_PROJECT_DIR/.cache/build" - - export GO_LDFLAGS="-X main.Tag=$CI_COMMIT_TAG -X main.Commit=$CI_COMMIT_SHA -X 'main.BuildTime=`date '+%b %_d %Y, %H:%M:%S'`'" - variables: - CGO_ENABLED: 0 - script: - - GOOS=linux GOARCH=amd64 go build -ldflags "$GO_LDFLAGS" -o mautrix-whatsapp_linux_amd64 - - GOOS=linux GOARCH=arm64 go build -ldflags "$GO_LDFLAGS" -o mautrix-whatsapp_linux_arm64 - - GOOS=linux GOARCH=arm go build -ldflags "$GO_LDFLAGS" -o mautrix-whatsapp_linux_arm - - GOOS=linux GOARCH=386 go build -ldflags "$GO_LDFLAGS" -o mautrix-whatsapp_linux_386 - artifacts: - paths: - - mautrix-whatsapp_linux_amd64 - - mautrix-whatsapp_linux_arm64 - - mautrix-whatsapp_linux_arm - - mautrix-whatsapp_linux_386 - - example-config.yaml - build amd64: <<: *build - tags: - - amd64 + image: dock.mau.dev/tulir/gomuks-build-docker:linux-amd64 build arm64: <<: *build - tags: - - arm64 + image: dock.mau.dev/tulir/gomuks-build-docker:linux-arm64 + +build arm: + <<: *build + image: dock.mau.dev/tulir/gomuks-build-docker:linux-arm build docker amd64: <<: *build-docker diff --git a/Dockerfile.ci b/Dockerfile.ci index 1f7ec81..d5e016f 100644 --- a/Dockerfile.ci +++ b/Dockerfile.ci @@ -1,14 +1,14 @@ FROM alpine:3.12 -ARG TARGETARCH=amd64 -ARG YQ_DOWNLOAD_ADDR=https://github.com/mikefarah/yq/releases/download/3.3.2/yq_linux_${TARGETARCH} +RUN echo $'\ +@edge http://dl-cdn.alpinelinux.org/alpine/edge/main\n\ +@edge http://dl-cdn.alpinelinux.org/alpine/edge/testing\n\ +@edge http://dl-cdn.alpinelinux.org/alpine/edge/community' >> /etc/apk/repositories ENV UID=1337 \ GID=1337 -RUN apk add --no-cache ffmpeg su-exec ca-certificates olm bash jq curl && \ - curl -sLo yq ${YQ_DOWNLOAD_ADDR} && \ - chmod +x yq && mv yq /usr/bin/yq +RUN apk add --no-cache ffmpeg su-exec ca-certificates bash jq curl yq@edge ARG EXECUTABLE=./mautrix-whatsapp COPY $EXECUTABLE /usr/bin/mautrix-whatsapp