Skip to content

Commit

Permalink
feat(container): Make it easier to run Kitten Science
Browse files Browse the repository at this point in the history
Moving to `docker-compose` as single solution to run environment.
Replacing `podman` with `docker`.
  • Loading branch information
oliversalzburg committed Oct 6, 2024
1 parent 3f7f2dd commit 72d014d
Show file tree
Hide file tree
Showing 50 changed files with 227 additions and 662 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"lint:prettier": "prettier --check packages",
"test": "yarn run test:all",
"test:all": "yarn workspaces foreach --all --exclude kitten-scientists --parallel --verbose run test",
"test:coverage:all": "yarn workspaces foreach --all --exclude kitten-scientists --parallel --verbose run test:coverage",
"typecheck:all": "tsc --noEmit --incremental false"
},
"workspaces": [
Expand Down
135 changes: 75 additions & 60 deletions package.json-scripts.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,82 +118,115 @@
"isGlobal": true,
"isRootManifest": false
},
{
"manifestPath": "packages/documentation/package.json",
"projectName": "@kitten-science/documentation",
"scriptName": "docs:nsd",
"scriptCode": "make nsd",
"isGlobal": true,
"isRootManifest": false,
"description": "Update the scripts reference that you are looking at right now."
},
{
"manifestPath": "packages/kitten-analysts/package.json",
"projectName": "@kitten-science/kitten-analysts",
"scriptName": "kitten-analysts:build",
"scriptName": "ka:build",
"scriptCode": "node build.js && vite --config vite.config.inject.js build",
"isGlobal": true,
"isRootManifest": false
},
{
"manifestPath": "packages/kitten-analysts/package.json",
"projectName": "@kitten-science/kitten-analysts",
"scriptName": "kitten-analysts:preview",
"scriptName": "ka:compose:build",
"scriptCode": "docker-compose build",
"isGlobal": true,
"isRootManifest": false
},
{
"manifestPath": "packages/kitten-analysts/package.json",
"projectName": "@kitten-science/kitten-analysts",
"scriptName": "ka:compose:down",
"scriptCode": "docker-compose down",
"isGlobal": true,
"isRootManifest": false
},
{
"manifestPath": "packages/kitten-analysts/package.json",
"projectName": "@kitten-science/kitten-analysts",
"scriptName": "ka:compose:up",
"scriptCode": "docker-compose up",
"isGlobal": true,
"isRootManifest": false
},
{
"manifestPath": "packages/kitten-analysts/package.json",
"projectName": "@kitten-science/kitten-analysts",
"scriptName": "ka:preview",
"scriptCode": "DEV_BUILD=true vite --config vite.config.userscript.js build",
"isGlobal": true,
"isRootManifest": false
},
{
"manifestPath": "packages/kitten-analysts/package.json",
"projectName": "@kitten-science/kitten-analysts",
"scriptName": "kitten-analysts:release",
"scriptName": "ka:release",
"scriptCode": "MINIFY=true vite --config vite.config.userscript.js build; vite --config vite.config.userscript.js build",
"isGlobal": true,
"isRootManifest": false
},
{
"manifestPath": "packages/kitten-analysts/package.json",
"projectName": "@kitten-science/kitten-analysts",
"scriptName": "kitten-analysts:start",
"scriptName": "ka:start",
"scriptCode": "node output/entrypoint-backend.js",
"isGlobal": true,
"isRootManifest": false
},
{
"manifestPath": "packages/kitten-engineers/package.json",
"projectName": "@kitten-science/kitten-engineers",
"scriptName": "kitten-engineers:build",
"scriptName": "ke:build",
"scriptCode": "vite --config vite.config.inject.js build",
"isGlobal": true,
"isRootManifest": false
},
{
"manifestPath": "packages/kitten-engineers/package.json",
"projectName": "@kitten-science/kitten-engineers",
"scriptName": "kitten-engineers:preview",
"scriptName": "ke:preview",
"scriptCode": "DEV_BUILD=true vite --config vite.config.userscript.js build",
"isGlobal": true,
"isRootManifest": false
},
{
"manifestPath": "packages/kitten-engineers/package.json",
"projectName": "@kitten-science/kitten-engineers",
"scriptName": "kitten-engineers:release",
"scriptName": "ke:release",
"scriptCode": "MINIFY=true vite --config vite.config.userscript.js build; vite --config vite.config.userscript.js build",
"isGlobal": true,
"isRootManifest": false
},
{
"manifestPath": "packages/kitten-engineers/package.json",
"projectName": "@kitten-science/kitten-engineers",
"scriptName": "kitten-engineers:version",
"scriptName": "ke:version",
"scriptCode": "node version.cjs",
"isGlobal": true,
"isRootManifest": false
},
{
"manifestPath": "packages/kitten-engineers/package.json",
"projectName": "@kitten-science/kitten-engineers",
"scriptName": "kitten-engineers:watch",
"scriptName": "ke:watch",
"scriptCode": "vite --config vite.config.inject.js build --watch",
"isGlobal": true,
"isRootManifest": false
},
{
"manifestPath": "packages/kitten-scientists/package.json",
"projectName": "@kitten-science/kitten-scientists",
"scriptName": "kitten-scientists:build",
"scriptName": "ks:build",
"scriptCode": "vite --config vite.config.inject.js build",
"isGlobal": true,
"isRootManifest": false,
Expand All @@ -202,7 +235,7 @@
{
"manifestPath": "packages/kitten-scientists/package.json",
"projectName": "@kitten-science/kitten-scientists",
"scriptName": "kitten-scientists:preview",
"scriptName": "ks:preview",
"scriptCode": "DEV_BUILD=true vite --config vite.config.userscript.js build",
"isGlobal": true,
"isRootManifest": false,
Expand All @@ -211,7 +244,7 @@
{
"manifestPath": "packages/kitten-scientists/package.json",
"projectName": "@kitten-science/kitten-scientists",
"scriptName": "kitten-scientists:release",
"scriptName": "ks:release",
"scriptCode": "MINIFY=true vite --config vite.config.userscript.js build; vite --config vite.config.userscript.js build",
"isGlobal": true,
"isRootManifest": false,
Expand All @@ -220,7 +253,7 @@
{
"manifestPath": "packages/kitten-scientists/package.json",
"projectName": "@kitten-science/kitten-scientists",
"scriptName": "kitten-scientists:version",
"scriptName": "ks:version",
"scriptCode": "node version.cjs",
"isGlobal": true,
"isRootManifest": false,
Expand All @@ -229,55 +262,39 @@
{
"manifestPath": "packages/kitten-scientists/package.json",
"projectName": "@kitten-science/kitten-scientists",
"scriptName": "kitten-scientists:watch",
"scriptName": "ks:watch",
"scriptCode": "vite --config vite.config.inject.js build --watch",
"isGlobal": true,
"isRootManifest": false,
"description": "Builds the Kitten Scientists userscript and watches all files for changes. If changes are detected, the script is rebuilt.\n\n!!! warning\n\n This watcher has caused problems in the past, generating broken output. Use at your own risk."
},
{
"manifestPath": "packages/kitten-analysts/package.json",
"projectName": "@kitten-science/kitten-analysts",
"scriptName": "kittenscience:build",
"scriptCode": "bash ./scripts/build-container.sh",
"isGlobal": true,
"isRootManifest": false
},
{
"manifestPath": "packages/kitten-analysts/package.json",
"projectName": "@kitten-science/kitten-analysts",
"scriptName": "kittenscience:rebuild",
"scriptCode": "bash ./scripts/rebuild-container.sh",
"isGlobal": true,
"isRootManifest": false
},
{
"manifestPath": "packages/kitten-analysts/package.json",
"projectName": "@kitten-science/kitten-analysts",
"scriptName": "kittenscience:run",
"scriptCode": "bash ./scripts/run-container.sh",
"isGlobal": true,
"manifestPath": "packages/devcontainer/package.json",
"projectName": "@kitten-science/devcontainer",
"scriptName": "lint",
"scriptCode": "yarn run lint:all",
"isGlobal": false,
"isRootManifest": false
},
{
"manifestPath": "packages/kitten-analysts/package.json",
"projectName": "@kitten-science/kitten-analysts",
"scriptName": "kittenscience:stop",
"scriptCode": "bash ./scripts/stop-container.sh",
"isGlobal": true,
"scriptName": "lint",
"scriptCode": "yarn run lint:all",
"isGlobal": false,
"isRootManifest": false
},
{
"manifestPath": "packages/devcontainer/package.json",
"projectName": "@kitten-science/devcontainer",
"manifestPath": "packages/kitten-engineers/package.json",
"projectName": "@kitten-science/kitten-engineers",
"scriptName": "lint",
"scriptCode": "yarn run lint:all",
"isGlobal": false,
"isRootManifest": false
},
{
"manifestPath": "packages/kitten-analysts/package.json",
"projectName": "@kitten-science/kitten-analysts",
"manifestPath": "packages/kitten-scientists/package.json",
"projectName": "@kitten-science/kitten-scientists",
"scriptName": "lint",
"scriptCode": "yarn run lint:all",
"isGlobal": false,
Expand Down Expand Up @@ -340,6 +357,22 @@
"isGlobal": false,
"isRootManifest": false
},
{
"manifestPath": "packages/kitten-engineers/package.json",
"projectName": "@kitten-science/kitten-engineers",
"scriptName": "test",
"scriptCode": "echo This project has no tests.",
"isGlobal": false,
"isRootManifest": false
},
{
"manifestPath": "packages/kitten-scientists/package.json",
"projectName": "@kitten-science/kitten-scientists",
"scriptName": "test",
"scriptCode": "echo This project has no tests.",
"isGlobal": false,
"isRootManifest": false
},
{
"manifestPath": "package.json",
"projectName": "kitten-scientists",
Expand All @@ -357,24 +390,6 @@
"isRootManifest": true,
"description": "Runs unit tests in all workspaces."
},
{
"manifestPath": "packages/action-release-info/package.json",
"projectName": "@kitten-science/action-release-info",
"scriptName": "test:coverage",
"scriptCode": "c8 --reporter html-spa --reporter text node --enable-source-maps $(yarn bin mocha) ./build/*.test.js",
"isGlobal": true,
"isRootManifest": false,
"description": "Runs unit tests in all workspaces and collects code coverage information."
},
{
"manifestPath": "package.json",
"projectName": "kitten-scientists",
"scriptName": "test:coverage:all",
"scriptCode": "yarn workspaces foreach --all --exclude kitten-scientists --parallel --verbose run test:coverage",
"isGlobal": true,
"isRootManifest": true,
"description": "Runs the `test:coverage` script in all workspaces."
},
{
"manifestPath": "packages/action-release-info/package.json",
"projectName": "@kitten-science/action-release-info",
Expand Down
2 changes: 0 additions & 2 deletions packages/action-release-info/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"build": "yarn tsc",
"clean": "rm -rf ./build ./tsconfig.tsbuildinfo",
"test": "node --enable-source-maps $(yarn bin mocha) ./build/*.test.js",
"test:coverage": "c8 --reporter html-spa --reporter text node --enable-source-maps $(yarn bin mocha) ./build/*.test.js",
"test:inspect": "node $(yarn bin mocha) --inspect ./build/*.test.js"
},
"types": "./build/index.d.ts",
Expand All @@ -37,7 +36,6 @@
"@types/chai": "5.0.0",
"@types/mocha": "10.0.8",
"@types/node": "22.7.4",
"c8": "10.1.2",
"chai": "5.1.1",
"mocha": "10.7.3",
"typescript": "5.6.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/devcontainer/scripts/build-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ main() {
REPO=${2:-https://github.com/nuclear-unicorn/kittensgame.git}

echo "Building development container on $BRANCH branch of $REPO..."
buildah bud \
docker build \
--build-arg BRANCH="$BRANCH" \
--build-arg REPO="$REPO" \
--file ./Containerfile \
Expand Down
2 changes: 1 addition & 1 deletion packages/devcontainer/scripts/rebuild-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ main() {
REPO=${2:-https://github.com/nuclear-unicorn/kittensgame.git}

echo "Re-Building development container on $BRANCH branch of $REPO..."
buildah bud \
docker build \
--build-arg BRANCH="$BRANCH" \
--build-arg REPO="$REPO" \
--file ./Containerfile \
Expand Down
8 changes: 4 additions & 4 deletions packages/devcontainer/scripts/run-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ main() {
echo "Done building Devcontainer."

echo "Removing previous container..."
podman kill devcontainer || true
podman rm devcontainer || true
docker kill devcontainer || true
docker rm devcontainer || true
echo "Previous container removed or non-existent."

echo ""

echo "Starting new container..."
# 8086 Live-Reload Websocket from Development HTTP Server
# 8100 Kittens Game Browser UI
podman run \
docker run \
--detach \
--mount type=bind,source="${BASEDIR}/../../kitten-analysts/output",target=/kittensgame/kitten-analysts \
--mount type=bind,source="${BASEDIR}/../../kitten-engineers/output",target=/kittensgame/kitten-engineers \
Expand All @@ -44,7 +44,7 @@ main() {
echo "Container started."

echo ""
echo "Kitten game should be running at http://127.0.0.1:8100"
echo "Kittens Game should be running at http://127.0.0.1:8100"
}

main "$@"
4 changes: 2 additions & 2 deletions packages/devcontainer/scripts/stop-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ cd "$(dirname "$0")"

main() {
echo "Removing container..."
podman kill devcontainer || true
podman rm devcontainer || true
docker kill devcontainer || true
docker rm devcontainer || true
echo "Previous container removed or non-existent."
}

Expand Down
5 changes: 4 additions & 1 deletion packages/documentation/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
python3 -m venv .venv
. .venv/bin/activate; pip install -r requirements.txt

public: .venv
.PHONY: nsd
nsd:
yarn nsd --cwd=../.. --docs-location="packages/documentation/docs/reference/Repository Scripts/"

public: .venv nsd
. .venv/bin/activate; mkdocs build --config-file mkdocs.yml --site-dir public

serve: .venv
Expand Down
9 changes: 2 additions & 7 deletions packages/documentation/docs/advanced/dna.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,10 @@ If you are not running the Kitten Science DnA environment, Kitten Analysts will

## How can I use it?

!!! warning

The current implementation expects you to have `podman` available for container networking. If you don't have it available, the command will fail and there is no alternative for now. Sorry.

Ideally, you only have to build and run the environment with two commands:
You should be able to bring up the environment with:

```shell
yarn kittenscience:build
yarn kittenscience:run
yarn ka:compose:up
```

The resulting pod should expose 4 ports:
Expand Down
2 changes: 1 addition & 1 deletion packages/documentation/docs/development/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The development environment is expected to be a POSIX-compliant system. On Windo

You will need [NodeJS](https://nodejs.org/) to be able to work with the project. The project uses [yarn](https://yarnpkg.com/) as a package and project manager, which is usually integrated with recent NodeJS versions.

Additionally, you will need to have [Podman](https://podman.io/get-started) available, to use the container-based Kittens Game development server. If you do not have Podman, you can still build a release version of the script and drop that into your userscript manager. You can also use Docker, or other container engines, but the existing tooling is built around `podman`.
Additionally, you will need to have [Docker](https://www.docker.com/) available, to use the container-based Kittens Game development server.

## General Development

Expand Down
Loading

0 comments on commit 72d014d

Please sign in to comment.