From aab8efb9e156ceff6a1f00e5761bdd4d95e3afb4 Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Sun, 1 Dec 2024 11:31:01 -0800 Subject: [PATCH] ci: add server build --- .github/workflows/ci.yml | 43 ++++++++++++++++++++++++++++++++++++ cmd/tunnel-server/Dockerfile | 21 ++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 cmd/tunnel-server/Dockerfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 51879a3..9d1cb35 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,3 +23,46 @@ jobs: - name: Run tests run: go test -v ./... + build-server: + runs-on: ubuntu-latest + needs: + - test + env: + # Check if this is not a fork as forks cannot push to ghcr + IS_NOT_FORK: ${{ github.repository == github.event.repository.full_name }} + steps: + - uses: actions/checkout@v4 + - uses: docker/setup-qemu-action@v3 + - uses: docker/setup-buildx-action@v3 + - name: Login to ghcr + if: ${{ env.IS_NOT_FORK == 'true' }} + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Set Metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ github.actor }}/tunnel-server + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + push: ${{ env.IS_NOT_FORK == 'true' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + ok: + runs-on: ubuntu-latest + needs: + - test + - build-server + if: always() + steps: + - run: | + if ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}; then + echo "One or more required jobs failed" + exit 1 + fi + echo "ok" diff --git a/cmd/tunnel-server/Dockerfile b/cmd/tunnel-server/Dockerfile new file mode 100644 index 0000000..2494800 --- /dev/null +++ b/cmd/tunnel-server/Dockerfile @@ -0,0 +1,21 @@ +# this dockerfile should be built from the root of the repository like: +# docker build . -f cmd/tunnel-server/Dockerfile +FROM golang:1.23-bullseye AS builder +WORKDIR /build + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . + +# Build the application +RUN go build -o /opt/tunnel-server ./cmd/tunnel-server + +# Use a minimal image for running the application +FROM debian:bullseye-slim + +# Copy the compiled binary +COPY --from=builder /opt/tunnel-server /opt/tunnel-server + +# Command to run the binary +CMD ["/opt/tunnel-server"]