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

On Releases, Build & Publish a docker image for the server #9

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
73 changes: 73 additions & 0 deletions .github/workflows/docker_server.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Publish Docker Containers

on:
push:
tags:
- "v[0-9]+.[0-9]+"

jobs:
# define job to build and publish docker image
build-and-push-docker-image:
name: Build Latest Docker image and push to repositories
# run only when code is compiling and tests are passing
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
include:
- dockerfile: ./Dockerfile
image: ghcr.io/${{ github.repository_owner }}/hacker-leauge-server
permissions:
contents: read
packages: write

# steps to perform in job
steps:
- name: Checkout code
uses: actions/checkout@v3

# setup Docker buld action
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2

# Setup "metadata"
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: ${{ matrix.image }}
# generate Docker tags based on the following events/attributes
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=pep440,pattern={{version}}
# type=semver,pattern=v{{major}}.{{minor}}
# type=semver,pattern={{version}}
# type=ref,event=pr
# type=semver,pattern={{major}}
# type=sha
# type=schedule

- name: Login to Github Packages
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: DEBUG
run: echo ${{ github.ref }}

- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
file: ${{ matrix.dockerfile }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Stage 1: Build stage
FROM debian:12.7 as build

# Set the working directory to /tmp
WORKDIR /tmp

RUN apt-get update && \
apt-get install -y curl

# Download the server binary
RUN curl -L -o server "https://github.com/moritztng/hacker-league/releases/latest/download/server_x86_64_debian"

# Stage 2: Final stage
FROM debian:12.7

# Set the working directory to /app
WORKDIR /app

EXPOSE 10000

RUN apt-get update && \
apt-get install -y libglfw3 libcurl4-openssl-dev && \
rm -rf /var/lib/apt/lists/*

# Copy the server binary from the build stage
COPY --from=build /tmp/server /app/server
RUN chmod +x /app/server

ENTRYPOINT ["/app/server", "10000"]