Skip to content

Commit

Permalink
GitHub action to build and publish
Browse files Browse the repository at this point in the history
  • Loading branch information
Lackronik committed Apr 24, 2024
1 parent bad12c4 commit 825a83d
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 0 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/build_img.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Build ARM image and Publish to ECR

on:
push:
branches:
- develop

env:
BUILD_PATH: './app/build/'

jobs:
build-and-push:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
repository: ${{ github.repository }}
ref: ${{ github.sha }}

- name: Install .NET Core SDK
uses: actions/setup-dotnet@v2
with:
dotnet-version: '7.0'

- name: Login to NuGet registry
run: |
dotnet nuget add source -u "${{ secrets.NUGET_GITHUB_USER }}" \
-p "${{ secrets.NUGET_GITHUB_TOKEN }}" \
--store-password-in-clear-text \
-n github "https://nuget.pkg.github.com/OSTOLEX-Technologies/index.json"
- name: Restore packages
run: dotnet restore "castledice-game-server/castledice-game-server.csproj"

- name: Create build directory
run: mkdir -p ${{ env.BUILD_PATH }}

- name: Build project
run: dotnet build castledice-game-server/castledice-game-server.csproj -c Release -r linux-musl-arm64 -o ${{ env.BUILD_PATH }}

- name: Copy service files
run: |
cp Dockerfile ${{ env.BUILD_PATH }}
cp entrypoint.sh ${{ env.BUILD_PATH }}
cp appsettings.json ${{ env.BUILD_PATH }}
cp nlog.config ${{ env.BUILD_PATH }}
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: ${{ env.BUILD_PATH }}
push: true
tags: ${{ steps.login-ecr.outputs.registry }}/castledice-game-server:latest
platforms: linux/amd64,linux/arm64
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM --platform=linux/arm64 130936542519.dkr.ecr.eu-central-1.amazonaws.com/castledice-riptide_server:latest

ARG NET_VERSION=7.0.14
ENV ASPNET_VERSION=$NET_VERSION

RUN apk --no-cache add jq

COPY . /app/
RUN cp /usr/share/dotnet/shared/Microsoft.NETCore.App/$NET_VERSION/*.so /app/

WORKDIR /app

RUN chmod +x entrypoint.sh

EXPOSE 7779

CMD ["sh", "/app/entrypoint.sh"]
17 changes: 17 additions & 0 deletions appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"GameServerStartOptions": {
"Port": 7779,
"MaxClientCount": 1000
},
"MatchMakerConnectionOptions": {
"Ip": "127.0.0.1",
"Port": 7777
},
"AuthBackendConnectionOptions": {
"Url": "http://auth.castledice.xyz:8000"
},
"StorageBackendConnectionOptions": {
"Url": "http://135.181.148.125:8080"
}
}

16 changes: 16 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

# Resolve "matchmaker" into IP
host_ip=$(getent hosts matchmaker | awk '{print $1}')

# Check if the host_ip is not empty
if [ -n "$host_ip" ]; then
# Update config JSON file with IP
jq --arg host_ip "$host_ip" '.MatchMakerConnectionOptions.Ip = $host_ip' appsettings.json > temp.json && mv temp.json appsettings.json
echo "JSON file updated successfully."
else
echo "Error: Unable to resolve the hostname."
exit 1
fi

dotnet /app/castledice-game-server.dll

0 comments on commit 825a83d

Please sign in to comment.