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

Enhancement (ci): Add <version>-layered-<date> tag for layered image #173

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
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-<date>` [(*/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-<date>`.

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