Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add server build #6

Merged
merged 1 commit into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,56 @@ 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 }}
DOCKER_IMAGE: ghcr.io/${{ github.actor }}/tunnel-server
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: ${{ env.DOCKER_IMAGE }}
- name: Build and Push
uses: docker/build-push-action@v5
env:
CACHE_FROM_CONFIG: "type=registry,ref=${{env.DOCKER_IMAGE}}:buildcache"
CACHE_TO_CONFIG: "type=registry,ref=${{env.DOCKER_IMAGE}}:buildcache,mode=max"
PLATFORMS: ${{ github.event_name == 'pull_request' && 'linux/amd64' || 'linux/amd64,linux/arm64' }}
with:
file: cmd/tunnel-server/Dockerfile
context: .
push: ${{ env.IS_NOT_FORK == 'true' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: ${{ env.CACHE_FROM_CONFIG }}
cache-to: ${{ github.event_name == 'push' && env.CACHE_TO_CONFIG || '' }}
platforms: ${{ env.PLATFORMS }}
ok:
runs-on: ubuntu-latest
needs:
- test
- build-server
if: ${{ !cancelled() }}
steps:
- name: Test needed jobs failed
run: |
if ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}; then
echo "One or more required jobs failed"
exit 1
fi
echo "ok"
21 changes: 21 additions & 0 deletions cmd/tunnel-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]