From 07064130611db66d374b7a98928812d47c5c42a3 Mon Sep 17 00:00:00 2001 From: Toni Spets Date: Mon, 5 Aug 2024 08:18:44 +0300 Subject: [PATCH] Add docker build stuff --- .github/workflows/deploy.yaml | 84 +++++++++++++++++++++++++++++++++++ Dockerfile | 19 ++++++++ build.sh | 9 ++++ 3 files changed, 112 insertions(+) create mode 100644 .github/workflows/deploy.yaml create mode 100644 Dockerfile create mode 100755 build.sh diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..343c3be --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -0,0 +1,84 @@ +name: Build and Deploy + +on: + push: + pull_request: + branches: [main] + +env: + GO_VERSION: 1.21 + BEEPER_BRIDGE_TYPE: dummybridge + CI_REGISTRY_IMAGE: "${{ secrets.CI_REGISTRY }}/bridge/dummybridge" + GHCR_REGISTRY: ghcr.io + GHCR_REGISTRY_IMAGE: "ghcr.io/${{ github.repository }}" + +jobs: + build-docker: + runs-on: ubuntu-latest + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to Beeper Docker registry + uses: docker/login-action@v2 + with: + registry: ${{ secrets.CI_REGISTRY }} + username: ${{ secrets.CI_REGISTRY_USER }} + password: ${{ secrets.CI_REGISTRY_PASSWORD }} + + - name: Login to ghcr + uses: docker/login-action@v2 + with: + registry: ${{ env.GHCR_REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Docker Build + uses: docker/build-push-action@v2 + with: + cache-from: ${{ env.CI_REGISTRY_IMAGE }}:latest + pull: true + file: Dockerfile + tags: | + ${{ env.CI_REGISTRY_IMAGE }}:${{ github.sha }} + ${{ env.GHCR_REGISTRY_IMAGE }}:${{ github.sha }} + push: true + + deploy-docker: + runs-on: ubuntu-latest + needs: + - build-docker + if: github.ref == 'refs/heads/main' + steps: + - name: Login to Beeper Docker registry + uses: docker/login-action@v2 + with: + registry: ${{ secrets.CI_REGISTRY }} + username: ${{ secrets.CI_REGISTRY_USER }} + password: ${{ secrets.CI_REGISTRY_PASSWORD }} + + - name: Login to ghcr + uses: docker/login-action@v2 + with: + registry: ${{ env.GHCR_REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - uses: beeper/docker-retag-push-latest@main + with: + image: ${{ env.CI_REGISTRY_IMAGE }} + + - uses: beeper/docker-retag-push-latest@main + with: + image: ${{ env.GHCR_REGISTRY_IMAGE }} + + - name: Run bridge CD tool + uses: beeper/bridge-cd-tool@main + env: + CI_REGISTRY: "${{ secrets.CI_REGISTRY }}" + BEEPER_DEV_ADMIN_API_URL: "${{ secrets.BEEPER_DEV_ADMIN_API_URL }}" + BEEPER_STAGING_ADMIN_API_URL: "${{ secrets.BEEPER_STAGING_ADMIN_API_URL }}" + BEEPER_PROD_ADMIN_API_URL: "${{ secrets.BEEPER_PROD_ADMIN_API_URL }}" + BEEPER_DEV_ADMIN_NIGHTLY_PASS: "${{ secrets.BEEPER_DEV_ADMIN_NIGHTLY_PASS }}" + BEEPER_STAGING_ADMIN_NIGHTLY_PASS: "${{ secrets.BEEPER_STAGING_ADMIN_NIGHTLY_PASS }}" + BEEPER_PROD_ADMIN_NIGHTLY_PASS: "${{ secrets.BEEPER_PROD_ADMIN_NIGHTLY_PASS }}" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6c73656 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM golang:1-alpine3.19 AS builder + +RUN apk add --no-cache git ca-certificates build-base su-exec olm-dev + +COPY . /build +WORKDIR /build +RUN ./build.sh + +FROM alpine:3.19 + +ENV UID=1337 \ + GID=1337 + +RUN apk add --no-cache su-exec ca-certificates olm bash jq yq curl + +COPY --from=builder /build/dummybridge /usr/bin/dummybridge +VOLUME /data + +CMD ["/bin/sh", "-c", "exec su-exec $UID:$GID /usr/bin/dummybridge"] diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..d692d97 --- /dev/null +++ b/build.sh @@ -0,0 +1,9 @@ +#!/bin/sh +MAUTRIX_VERSION=$(cat go.mod | grep 'maunium.net/go/mautrix ' | awk '{ print $2 }') +GO_LDFLAGS="-X main.Tag=$(git describe --exact-match --tags 2>/dev/null) -X main.Commit=$(git rev-parse HEAD) -X 'main.BuildTime=`date -Iseconds`' -X 'maunium.net/go/mautrix.GoModVersion=$MAUTRIX_VERSION'" +if [ "$DBG" = 1 ]; then + GO_GCFLAGS='all=-N -l' +else + GO_LDFLAGS="-s -w ${GO_LDFLAGS}" +fi +go build -gcflags="$GO_GCFLAGS" -ldflags="$GO_LDFLAGS" -o dummybridge ./cmd/dummybridge "$@"