Skip to content

Commit be9efa5

Browse files
committed
Add CI/CD to automatically create a Docker Image on push
- Every commit to `main`/`dev` will create an image tag - Every git tag will create an image tag - The latest tag is automatically handled by the meta step and will be set to the latest git tag
1 parent f8d307f commit be9efa5

6 files changed

Lines changed: 82 additions & 6 deletions

File tree

.github/workflows/deploy-image.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#
2+
name: Create and publish a Docker image
3+
4+
# Configures this workflow to run every time a change is pushed to the branch called `main`.
5+
on:
6+
push:
7+
branches: ['main', 'dev']
8+
tags: ['*']
9+
10+
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
11+
env:
12+
REGISTRY: ghcr.io
13+
IMAGE_NAME: ${{ github.repository }}
14+
15+
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
16+
jobs:
17+
build-and-push-image:
18+
runs-on: ubuntu-latest
19+
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
20+
permissions:
21+
contents: read
22+
packages: write
23+
attestations: write
24+
id-token: write
25+
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v4
29+
30+
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
31+
- name: Log in to the Container registry
32+
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
33+
with:
34+
registry: ${{ env.REGISTRY }}
35+
username: ${{ github.actor }}
36+
password: ${{ secrets.GITHUB_TOKEN }}
37+
38+
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
39+
# It will automatically create the latest Docker tag, if a git tag is found: https://github.com/docker/metadata-action?tab=readme-ov-file#latest-tag
40+
- name: Extract metadata (tags, labels) for Docker
41+
id: meta
42+
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
43+
with:
44+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
45+
46+
# This step gets the short git commit hash
47+
# https://dev.to/hectorleiva/github-actions-and-creating-a-short-sha-hash-8b7
48+
- name: Set short git commit SHA
49+
id: vars
50+
run: |
51+
calculatedSha=$(git rev-parse --short ${{ github.sha }})
52+
echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV
53+
54+
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
55+
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see [Usage](https://github.com/docker/build-push-action#usage) in the README of the `docker/build-push-action` repository.
56+
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
57+
- name: Build and push Docker image
58+
id: push
59+
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
60+
with:
61+
context: .
62+
push: true
63+
tags: ${{ steps.meta.outputs.tags }}
64+
labels: ${{ steps.meta.outputs.labels }}
65+
build-args: |
66+
GAME_GIT_HASH=${{ github.sha }}
67+
GAME_GIT_HASH_SHORT=${{ env.COMMIT_SHORT_SHA }}
68+
69+
# This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see [Using artifact attestations to establish provenance for builds](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds).
70+
- name: Generate artifact attestation
71+
uses: actions/attest-build-provenance@v2
72+
with:
73+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
74+
subject-digest: ${{ steps.push.outputs.digest }}
75+
push-to-registry: true

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// Editor formatting
2020
"editor.tabSize": 4,
2121
"editor.insertSpaces": false,
22-
"editor.detectIndentation": false,
22+
"editor.detectIndentation": true,
2323

2424
// Pylance / Pyright
2525
"python.analysis.typeCheckingMode": "strict",
@@ -220,6 +220,7 @@
220220
"TIMESYNC",
221221
"tweens",
222222
"tzdata",
223+
"unforgeable",
223224
"upleft",
224225
"upscaled",
225226
"usecase",

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ENV GAME_GIT_HASH_SHORT=$GAME_GIT_HASH_SHORT
1515
# https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys
1616
MAINTAINER Max Planck Institute for Security and Privacy
1717
LABEL org.opencontainers.image.authors="Max Planck Institute for Security and Privacy"
18-
LABEL org.opencontainers.image.version="2.0.3"
18+
LABEL org.opencontainers.image.version="2.0.4"
1919
LABEL org.opencontainers.image.licenses="AGPL-3.0-only"
2020
LABEL org.opencontainers.image.description="Ready to deploy Docker container to use ReverSim for research. ReverSim is an open-source environment for the browser, originally developed at the Max Planck Institute for Security and Privacy (MPI-SP) to study human aspects in hardware reverse engineering."
2121
LABEL org.opencontainers.image.source="https://github.com/emsec/ReverSim"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ You can try out ReverSim on our public demo instance at [beta.hrestudy.com](http
1414
To customize the sequence of tasks, change game rules, or to collect data for your own research, you will have to install the game on your own hardware.\
1515
We provide three ways to install and run the ReverSim server:
1616

17-
1. With [Docker](https://www.docker.com/) (preferred for production use): `docker run -it ghcr.io/emsec/reversim:latest`
17+
1. With [Docker](https://www.docker.com/) (preferred for production use): `docker run -it -p 8000:8000 ghcr.io/emsec/reversim:latest`
1818
2. With the [VS Code](https://code.visualstudio.com/) Python debugger (for testing only)
1919
3. From the command prompt (alternative)
2020

app/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
# CONFIG Current Log File Version
1818
# 1.Milestone.Subversion
19-
LOGFILE_VERSION = "2.0.3"
19+
LOGFILE_VERSION = "2.0.4"
2020

2121
PSEUDONYM_LENGTH = 32
2222
LEVEL_ENCODING = 'UTF-8' # was Windows-1252
@@ -297,7 +297,7 @@ def getGroupsDisabledErrorLogging() -> list[str]:
297297
return __configStorage['crashReportBlacklist']
298298
else:
299299
return [
300-
name for name, conf in __configStorage['groups'].items() if conf['config']['enableLogging'] == False
300+
name for name, conf in __configStorage['groups'].items() if not conf['config']['enableLogging']
301301
]
302302

303303

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ services:
2525
# the container will be named reversim_game when launched
2626
game:
2727
# adjust this, if you wan't to pull a different version/tag of the game
28-
image: reversim:latest
28+
image: ghcr.io/emsec/reversim:latest
2929
restart: unless-stopped
3030

3131
ports:

0 commit comments

Comments
 (0)