Skip to content
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
345 changes: 345 additions & 0 deletions .github/workflows/game.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,345 @@
name: "game build, push"

on:
workflow_dispatch:
push:
branches:
- main
- dev
paths:
- "server/**"
- ".github/workflows/**"
- "client_lib/**"
- "my-core-bot/**"
pull_request:
paths:
- "server/**"
- ".github/workflows/**"
- "client_lib/**"
- "my-core-bot/**"

permissions:
contents: read
packages: write

env:
SERVER_IMAGE: ghcr.io/42core-team/server
BOT_IMAGE: ghcr.io/42core-team/my-core-bot
RUNNER_AMD64: &RUNNER_AMD64 ubuntu-24.04 # set this to ubuntu-24.04 for github hosted runners and X64 for self-hosted runners
RUNNER_ARM64: &RUNNER_ARM64 ubuntu-24.04-arm # set this to ubuntu-24.04-arm for github hosted runners and ARM64 for self-hosted runners

concurrency:
group: "${{ github.workflow }} @ ${{ github.ref_name }}"
cancel-in-progress: true

jobs:
# PR validation for server image (no push)
pr-server:
if: github.event_name == 'pull_request'
runs-on: *RUNNER_AMD64
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: true

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Prepare
run: |
platform=linux/amd64
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV

- name: Build server (test only, export tar)
uses: docker/build-push-action@v6
with:
context: ${{ github.workspace }}
file: .github/workflows/server-Dockerfile
platforms: linux/amd64
push: false
tags: local/server:pr-${{ github.event.pull_request.head.sha }}
outputs: type=docker,dest=/tmp/server-image.tar
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Upload server image tar (PR)
uses: actions/upload-artifact@v4
with:
name: server-image-${{ env.PLATFORM_PAIR }}
path: /tmp/server-image.tar
if-no-files-found: error
retention-days: 1

# PR validation for my-core-bot image (no push)
pr-my-core-bot:
if: github.event_name == 'pull_request'
needs: pr-server
runs-on: *RUNNER_AMD64
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Prepare
run: |
platform=linux/amd64
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV

- name: Download server image tar (PR)
uses: actions/download-artifact@v4
with:
name: server-image-${{ env.PLATFORM_PAIR }}
path: ${{ runner.temp }}/server-image

- name: Load server image into Docker
run: |
docker load -i ${{ runner.temp }}/server-image/server-image.tar
docker image inspect local/server:pr-${{ github.event.pull_request.head.sha }} || docker tag $(docker images --format '{{.Repository}}:{{.Tag}}' | head -n1) local/server:pr-${{ github.event.pull_request.head.sha }}

# Switch builder to docker driver so it can see locally-loaded images
- name: Set up Docker Buildx (driver=docker)
id: builder-docker
uses: docker/setup-buildx-action@v3
with:
driver: docker
install: true
use: true

- name: Build my-core-bot (test only)
uses: docker/build-push-action@v6
with:
context: ${{ github.workspace }}
file: .github/workflows/my-core-bot-Dockerfile
builder: ${{ steps.builder-docker.outputs.name }}
build-args: |
SERVER_IMAGE=local/server
TAG_NAME=pr-${{ github.event.pull_request.head.sha }}
platforms: linux/amd64
pull: false
push: false

# Push-time: build and push server image (per-arch)
push-server-build:
if: github.event_name != 'pull_request'
strategy:
fail-fast: false
matrix:
include:
- architecture: amd64
runner: *RUNNER_AMD64
platform: linux/amd64
- architecture: arm64
runner: *RUNNER_ARM64
platform: linux/arm64
runs-on:
- ${{ matrix.runner }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: true

- name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV

# - name: Set up QEMU
# uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Docker meta (server)
id: meta-server
uses: docker/metadata-action@v5
with:
images: ${{ env.SERVER_IMAGE }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push by digest (server)
id: build-server
uses: docker/build-push-action@v6
with:
context: ${{ github.workspace }}
file: .github/workflows/server-Dockerfile
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta-server.outputs.labels }}
tags: ${{ env.SERVER_IMAGE }}
outputs: type=image,push-by-digest=true,name-canonical=true,push=true
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Export digest (server)
run: |
mkdir -p ${{ runner.temp }}/digests
digest="${{ steps.build-server.outputs.digest }}"
touch "${{ runner.temp }}/digests/${digest#sha256:}"

- name: Upload digest (server)
uses: actions/upload-artifact@v4
with:
name: server-digests-${{ env.PLATFORM_PAIR }}
path: ${{ runner.temp }}/digests/*
if-no-files-found: error
retention-days: 1

# Push-time: create and push multi-arch manifest for server
push-server-merge:
if: github.event_name != 'pull_request'
runs-on: *RUNNER_AMD64
needs: push-server-build
steps:
- name: Download digests (server)
uses: actions/download-artifact@v4
with:
path: ${{ runner.temp }}/digests
pattern: server-digests-*
merge-multiple: true

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Docker meta (server)
id: meta-server
uses: docker/metadata-action@v5
with:
images: ${{ env.SERVER_IMAGE }}
tags: |
type=raw,value=${{ github.ref_name }}
type=raw,value=${{ github.ref_name }}-${{ github.sha }}

- name: Create manifest list and push (server)
working-directory: ${{ runner.temp }}/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.SERVER_IMAGE }}@sha256:%s ' *)

- name: Inspect image (server)
run: |
docker buildx imagetools inspect ${{ env.SERVER_IMAGE }}:${{ steps.meta-server.outputs.version }}

# Push-time: build and push my-core-bot image after server manifest is ready
push-bot-build:
if: github.event_name != 'pull_request'
needs: push-server-merge
strategy:
fail-fast: true
matrix:
include:
- architecture: amd64
runner: *RUNNER_AMD64
platform: linux/amd64
- architecture: arm64
runner: *RUNNER_ARM64
platform: linux/arm64
runs-on:
- ${{ matrix.runner }}
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Docker meta (my-core-bot)
id: meta-bot
uses: docker/metadata-action@v5
with:
images: ${{ env.BOT_IMAGE }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push by digest (my-core-bot)
id: build-bot
uses: docker/build-push-action@v6
with:
context: ${{ github.workspace }}
file: .github/workflows/my-core-bot-Dockerfile
build-args: |
TAG_NAME=${{ github.ref_name }}
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta-bot.outputs.labels }}
tags: ${{ env.BOT_IMAGE }}
outputs: type=image,push-by-digest=true,name-canonical=true,push=true
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Export digest (my-core-bot)
run: |
mkdir -p ${{ runner.temp }}/digests-bot
digest="${{ steps.build-bot.outputs.digest }}"
touch "${{ runner.temp }}/digests-bot/${digest#sha256:}"

- name: Upload digest (my-core-bot)
uses: actions/upload-artifact@v4
with:
name: bot-digests-${{ env.PLATFORM_PAIR }}
path: ${{ runner.temp }}/digests-bot/*
if-no-files-found: error
retention-days: 1

# Push-time: create and push multi-arch manifest for my-core-bot
push-bot-merge:
if: github.event_name != 'pull_request'
runs-on: *RUNNER_AMD64
needs: push-bot-build
steps:
- name: Download digests (my-core-bot)
uses: actions/download-artifact@v4
with:
path: ${{ runner.temp }}/digests-bot
pattern: bot-digests-*
merge-multiple: true

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Docker meta (my-core-bot)
id: meta-bot
uses: docker/metadata-action@v5
with:
images: ${{ env.BOT_IMAGE }}
tags: |
type=raw,value=${{ github.ref_name }}
type=raw,value=${{ github.ref_name }}-${{ github.sha }}

- name: Create manifest list and push (my-core-bot)
working-directory: ${{ runner.temp }}/digests-bot
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.BOT_IMAGE }}@sha256:%s ' *)

- name: Inspect image (my-core-bot)
run: |
docker buildx imagetools inspect ${{ env.BOT_IMAGE }}:${{ steps.meta-bot.outputs.version }}
33 changes: 33 additions & 0 deletions .github/workflows/my-core-bot-Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
ARG TAG_NAME="dev"
ARG SERVER_IMAGE="ghcr.io/42core-team/server"

FROM ubuntu:noble AS ubuntu-gcc
ENV DEBIAN_FRONTEND=noninteractive

RUN apt update && \
apt install -y git build-essential libcurl4 && \
rm -rf /var/lib/apt/lists/*

FROM ${SERVER_IMAGE}:${TAG_NAME} AS game

# Build connection library from monorepo sources
FROM ubuntu-gcc AS connection
WORKDIR /connection
COPY client_lib/ ./
RUN make re

FROM ubuntu-gcc AS release

# COPY .bashrc /root/.bashrc
COPY --from=game /core/server /core/server
COPY --from=game /core/data /core/data
COPY --from=connection /connection/inc/core_lib.h /core/core_lib.h
COPY --from=connection /connection/core_lib.a /core/core_lib.a
# Also provide legacy name if expected by consumers
COPY --from=connection /connection/core_lib.a /core/con_lib.a

# Create .bashrc in /root/ directory by curling from URL
# RUN curl -o /root/.bashrc https://raw.githubusercontent.com/42core-team/.shellrc/refs/heads/main/.bashrc

# SHELL ["/bin/bash", "-c"]
# ENV SHELL=/bin/bash
Loading