Skip to content

Commit

Permalink
Add publishing images to DockerHub (#496)
Browse files Browse the repository at this point in the history
* Add Dockerfile and publishing to DockerHub

* Add docker badge to readme

* Fix inventory saving #497

* Remove prayer debug info

* Fix level up

* Reuse Properties in koin
  • Loading branch information
GregHib authored Mar 19, 2024
1 parent 2ed53b8 commit 0743852
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 27 deletions.
59 changes: 53 additions & 6 deletions .github/workflows/create_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,69 @@ jobs:
contents: write
steps:
- uses: actions/checkout@v4
- name: Log in to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Create cache folder
run: mkdir -p data/cache/
- uses: actions/setup-java@v3
with:
java-version: '19'
distribution: 'temurin'
java-version: "19"
distribution: "temurin"
architecture: x64
cache: 'gradle'
cache: "gradle"
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v1
- name: Grant permissions to gradlew
- name: Check if secrets exists
id: check_secret
run: |
if [ -n "${{ secrets.AWS_ACCESS_KEY_ID }}" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Grant Permissions to gradlew
run: chmod +x gradlew
- name: Get cache version
run: echo "cache_version=$(./gradlew -q printCacheVersion)" >> $GITHUB_ENV
- name: Get build version
run: echo "build_version=$(./gradlew -q printVersion)" >> $GITHUB_ENV
- name: Cache game files
if: steps.check_secret.outputs.exists == 'true'
id: cache-files
uses: actions/cache@v3
with:
key: cache-${{ env.cache_version }}-${{ hashFiles('data/cache/main_file_cache.idx255') }}
path: data/cache/
enableCrossOsArchive: 'true'
restore-keys:
cache-${{ env.cache_version }}
cache-
- if: steps.check_secret.outputs.exists == 'true' && steps.cache-files.outputs.cache-hit != 'true'
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: eu-west-2
run: aws s3 cp --recursive s3://void-rsps/caches/${{ env.CACHE_VERSION }}/ data/cache/
- name: Run distribution assembly
run: ./gradlew buildScripts assembleBundleDist
run: ./gradlew assembleBundleDist
- name: Upload distribution
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run:
gh release create -d ${{ github.ref_name }} ./game/build/distributions/void-${{ env.build_version }}.zip
gh release create -d ${{ github.ref_name }} ./game/build/distributions/void-${{ env.build_version }}.zip
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: greghib/void
- name: Build and push Docker image
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
27 changes: 17 additions & 10 deletions .github/workflows/test-with-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ on:
env:
CACHE_VERSION: 1.2.0
jobs:
build-test:
name: Build & Test
test:
name: Test
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
Expand All @@ -18,34 +18,41 @@ jobs:
run: mkdir -p data/cache/
- uses: actions/setup-java@v3
with:
java-version: '19'
distribution: 'temurin'
java-version: "19"
distribution: "temurin"
architecture: x64
cache: 'gradle'
cache: "gradle"
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v1
- name: Check if secrets exists
id: check_secret
run: echo ::set-output name=exists::$(if [ -n "${{ secrets.AWS_ACCESS_KEY_ID }}" ]; then echo "true"; else echo "false"; fi)
run: |
if [ -n "${{ secrets.AWS_ACCESS_KEY_ID }}" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Grant Permissions to gradlew
run: chmod +x gradlew
- name: Get cache version
run: echo "cache_version=$(./gradlew -q printCacheVersion)" >> $GITHUB_ENV
- name: Cache game files
if: steps.check_secret.outputs.exists == 'true'
id: cache-files
uses: actions/cache@v3
with:
key: cache-${{ env.CACHE_VERSION }}-${{ hashFiles('data/cache/main_file_cache.idx255') }}
key: cache-${{ env.cache_version }}-${{ hashFiles('data/cache/main_file_cache.idx255') }}
path: data/cache/
enableCrossOsArchive: 'true'
restore-keys:
cache-${{ env.CACHE_VERSION }}
cache-${{ env.cache_version }}
cache-
- if: steps.check_secret.outputs.exists == 'true' && steps.cache-files.outputs.cache-hit != 'true'
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: eu-west-2
run: aws s3 cp --recursive s3://void-rsps/caches/${{ env.CACHE_VERSION }}/ data/cache/
- name: Grant Permissions to gradlew
run: chmod +x gradlew
- name: Run all tests
if: steps.check_secret.outputs.exists == 'true'
run: ./gradlew test
Expand Down
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM eclipse-temurin:19-jdk-alpine
LABEL authors="Greg"
EXPOSE 43594/tcp

RUN mkdir /app
WORKDIR /app/

# Copy JAR file
COPY ./game/build/libs/void-server-*.jar /app/void-server.jar

# Copy configuration and cache files
COPY ./data/map/ /app/data/map/
COPY ./data/spawns/ /app/data/spawns/
COPY ./data/definitions/ /app/data/definitions/
COPY ./data/cache/ /app/data/cache/

CMD ["java", "-jar", "void-server.jar"]
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
</a>

[![Release](https://github.com/GregHib/void/actions/workflows/create_release.yml/badge.svg)](https://github.com/GregHib/void/actions/workflows/create_release.yml)
[![codecov](https://codecov.io/gh/GregHib/void/graph/badge.svg?token=7W6PTSHUTT)](https://codecov.io/gh/GregHib/void)
[![Kotlin](https://img.shields.io/badge/kotlin-1.9.22-blue.svg?logo=kotlin)](http://kotlinlang.org)
[![Docker](https://img.shields.io/badge/Docker-latest-blue.svg?logo=docker)](https://hub.docker.com/r/greghib/void)
[![Codecov](https://codecov.io/gh/GregHib/void/graph/badge.svg?token=7W6PTSHUTT)](https://codecov.io/gh/GregHib/void)
[![Kotlin](https://img.shields.io/badge/Kotlin-1.9.22-blue.svg?logo=kotlin)](http://kotlinlang.org)
[![License](https://img.shields.io/badge/License-BSD_3--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)

<h1>RuneScape Revived</h1>
Expand Down
8 changes: 8 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ plugins {
id("jacoco-report-aggregation")
}

val cacheVersion = "1.2.0"

allprojects {
apply(plugin = "kotlin")
apply(plugin = "idea")
Expand Down Expand Up @@ -75,6 +77,12 @@ tasks.register("printVersion") {
}
}

tasks.register("printCacheVersion") {
doLast {
println(cacheVersion)
}
}


reporting {
reports {
Expand Down
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: "3.8"
services:
void:
image: greghib/void
volumes:
- ./data/saves/:/app/data/saves
ports:
- "43594:43594"
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal fun Player.copy() = PlayerSave(
looks = body.looks.copyOf(),
colours = body.colours.copyOf(),
variables = variables.data.toMap(),
inventories = inventories.inventories.mapValues { it.value.copyOf() },
inventories = inventories.inventories.mapValues { (inventories.instances[it.key]?.items ?: it.value).map { itm -> itm.copy() }.toTypedArray() },
friends = friends.mapValues { it.value.name },
ignores = ignores.toList()
)
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class PrayerDefinitions {
}
this.prayers = Array(prayers.size) { prayers[it] }
this.curses = Array(curses.size) { curses[it] }
println(this.prayers.mapIndexed { index, prayerDefinition -> index to prayerDefinition.stringId })
this.groups = groups
this.definitions = definitions
this.definitions.size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import world.gregs.voidps.engine.event.Events
*/
data class CurrentLevelChanged(val skill: Skill, val from: Int, val to: Int) : CancellableEvent() {

override val notification = true

override val size = 5

override fun parameter(dispatcher: EventDispatcher, index: Int) = when (index) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import world.gregs.voidps.engine.event.Events
*/
data class MaxLevelChanged(val skill: Skill, val from: Int, val to: Int) : Event {

override val notification = true

override val size = 5

override fun parameter(dispatcher: EventDispatcher, index: Int) = when (index) {
Expand Down
4 changes: 3 additions & 1 deletion game/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,6 @@ distributions {
}

tasks["bundleDistTar"].dependsOn("buildScripts")
tasks["bundleDistZip"].dependsOn("buildScripts")
tasks["bundleDistZip"].dependsOn("buildScripts")
tasks["bundleDistTar"].dependsOn("startScripts")
tasks["bundleDistZip"].dependsOn("startScripts")
13 changes: 8 additions & 5 deletions game/src/main/kotlin/world/gregs/voidps/Main.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package world.gregs.voidps

import com.github.michaelbull.logging.InlineLogger
import kotlinx.coroutines.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.runBlocking
import org.koin.core.context.startKoin
import org.koin.core.logger.Level
import org.koin.dsl.module
import org.koin.fileProperties
import org.koin.logger.slf4jLogger
import world.gregs.voidps.cache.Cache
import world.gregs.voidps.cache.Index
Expand All @@ -14,10 +14,12 @@ import world.gregs.voidps.cache.config.decoder.StructDecoder
import world.gregs.voidps.cache.definition.decoder.*
import world.gregs.voidps.cache.secure.Huffman
import world.gregs.voidps.engine.*
import world.gregs.voidps.engine.client.*
import world.gregs.voidps.engine.client.ClientManager
import world.gregs.voidps.engine.client.ConnectionQueue
import world.gregs.voidps.engine.client.LoginManager
import world.gregs.voidps.engine.client.PlayerAccountLoader
import world.gregs.voidps.engine.data.definition.*
import world.gregs.voidps.engine.entity.World
import world.gregs.voidps.engine.entity.character.player.Players
import world.gregs.voidps.engine.map.collision.CollisionDecoder
import world.gregs.voidps.network.GameServer
import world.gregs.voidps.network.LoginServer
Expand Down Expand Up @@ -87,11 +89,12 @@ object Main : CoroutineScope {
return@timed properties
}

@Suppress("UNCHECKED_CAST")
private fun preload(cache: Cache, properties: Properties) {
val module = cache(cache, properties)
startKoin {
slf4jLogger(level = Level.ERROR)
fileProperties("/game.properties")
properties(properties.toMap() as Map<String, Any>)
modules(engineModule, gameModule, module)
}
val saves = File(getProperty("savePath"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ experience { player ->
}

maxLevelChange { player ->
if (from <= to) {
if (from >= to) {
return@maxLevelChange
}
if (player["skip_level_up", false]) {
Expand Down

0 comments on commit 0743852

Please sign in to comment.