Skip to content

Commit

Permalink
Enhancement (ci): Add <version>-layered-<date> tag for layered image
Browse files Browse the repository at this point in the history
Co-authored-by: leo <[email protected]>
  • Loading branch information
joeltimothyoh and leojonathanoh committed Dec 4, 2023
1 parent e6b28e0 commit 610cf87
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* `latest` [(*/build/Dockerfile*)][dockerfile-build-link], [(*/update/Dockerfile*)][dockerfile-update-link]
* `<version>` [(*/build/Dockerfile*)][dockerfile-build-link]
* `<version>-layered` [(*/update/Dockerfile*)][dockerfile-update-link]
* `<version>-layered-<calver>` [(*/update/Dockerfile*)][dockerfile-update-link]

[dockerfile-build-link]: https://github.com/startersclan/docker-sourceservers/blob/master/build/Dockerfile
[dockerfile-update-link]: https://github.com/startersclan/docker-sourceservers/blob/master/update/Dockerfile
Expand Down Expand Up @@ -159,7 +160,7 @@ Dedicated servers hosted on Steam are usually required to be running the *latest

### Game versions & tags

A *layered* image of a game is but a *clean* image compounded with game update layers. *Clean* images are tagged by `<version>`, while *layered* images are tagged by `<version>-layered`.
A *layered* image of a game is but a *clean* image compounded with game update layers. *Clean* images are tagged by `<version>`, while *layered* images are tagged by `<version>-layered` and `<version>-layered-<calver>`.

The `latest` tag of each game points to the game's newest *layered* image unless a newer *clean* image has been built with the `latest` tag. Thus, by using the `latest` tag, *layered* images are almost always used, circumventing the need to pull entire *clean* images for obtaining game updates.

Expand Down
18 changes: 11 additions & 7 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ if [ "$PIPELINE" = 'build' ]; then
BUILD_CONTEXT='build/'
elif [ "$PIPELINE" = 'update' ]; then
GAME_IMAGE_LAYERED="$DOCKER_REPOSITORY:$GAME_VERSION-layered"
GAME_IMAGE_LAYERED_CALVER="$GAME_IMAGE_LAYERED-$( date -u '+%Y%m%d' )"
BUILD_CONTEXT='update/'
fi
GAME_IMAGE_LATEST="$DOCKER_REPOSITORY:latest"
Expand Down Expand Up @@ -222,10 +223,9 @@ fi

# Build / Update the game image
if [ "$PIPELINE" = 'build' ]; then
GAME_IMAGE="$GAME_IMAGE_CLEAN"
if [ "$CACHE" = 'true' ]; then
date -Iseconds
time docker pull "$GAME_IMAGE" || true
time docker pull "$GAME_IMAGE_CLEAN" || true
fi
date -Iseconds
STEAM_USERNAME="$STEAM_USERNAME" STEAM_PASSWORD="$STEAM_PASSWORD" time docker build \
Expand All @@ -240,7 +240,7 @@ if [ "$PIPELINE" = 'build' ]; then
--build-arg INSTALL_COUNT="$INSTALL_COUNT" \
--build-arg STEAM_LOGIN="$STEAM_LOGIN" \
--build-arg CACHE_KEY="$GAME_VERSION" \
-t "$GAME_IMAGE" \
-t "$GAME_IMAGE_CLEAN" \
--label "appid=$APPID" \
--label "mod=$MOD" \
--label "client_appid=$CLIENT_APPID" \
Expand All @@ -252,11 +252,11 @@ if [ "$PIPELINE" = 'build' ]; then
--label "commit_sha=$COMMIT_SHA" \
"$BUILD_CONTEXT"
if [ "$LATEST" = 'true' ]; then
docker tag "$GAME_IMAGE" "$GAME_IMAGE_LATEST"
docker tag "$GAME_IMAGE_CLEAN" "$GAME_IMAGE_LATEST"
fi
date -Iseconds
GAME_IMAGE="$GAME_IMAGE_CLEAN"
elif [ "$PIPELINE" = 'update' ]; then
GAME_IMAGE="$GAME_IMAGE_LAYERED"
date -Iseconds
if [ ! "$NO_PULL" = 'true' ]; then
time docker pull "$GAME_IMAGE_LATEST"
Expand All @@ -271,13 +271,15 @@ elif [ "$PIPELINE" = 'update' ]; then
--build-arg INSTALL_COUNT="$INSTALL_COUNT" \
--build-arg STEAM_LOGIN="$STEAM_LOGIN" \
--build-arg CACHE_KEY="$GAME_VERSION" \
-t "$GAME_IMAGE" \
-t "$GAME_IMAGE_LAYERED" \
-t "$GAME_IMAGE_LAYERED_CALVER" \
-t "$GAME_IMAGE_LATEST" \
--label "game_version=$GAME_VERSION" \
--label "game_update_count=$GAME_UPDATE_COUNT" \
--label "commit_sha=$COMMIT_SHA" \
"$BUILD_CONTEXT"
date -Iseconds
GAME_IMAGE="$GAME_IMAGE_LAYERED"
fi
docker images
docker inspect "$GAME_IMAGE"
Expand Down Expand Up @@ -331,12 +333,14 @@ fi
# Push the game image
if [ ! "$NO_PUSH" = 'true' ]; then
date -Iseconds
time docker push "$GAME_IMAGE"
if [ "$PIPELINE" = 'build' ]; then
time docker push "$GAME_IMAGE_CLEAN"
if [ "$LATEST" = 'true' ]; then
time docker push "$GAME_IMAGE_LATEST"
fi
elif [ "$PIPELINE" = 'update' ]; then
time docker push "$GAME_IMAGE_LAYERED"
time docker push "$GAME_IMAGE_LAYERED_CALVER"
time docker push "$GAME_IMAGE_LATEST"
fi
date -Iseconds
Expand Down

0 comments on commit 610cf87

Please sign in to comment.