mirror of
				https://github.com/kevinveenbirkenbach/computer-playbook.git
				synced 2025-10-31 02:10:05 +00:00 
			
		
		
		
	feat(web-app-chess): add castling.club role with ports, networks, and build setup
- Added network subnet (192.168.103.192/28) and port 8050 for web-app-chess - Replaced stub README with usability-focused description of castling.club - Implemented config, vars, meta, and tasks for web-app-chess - Added Dockerfile, docker-compose.yml, env, and docker-entrypoint.sh templates - Integrated entrypoint asset placement - Updated meta to reflect usability and software features Ref: https://chatgpt.com/share/68b6c65a-3de8-800f-86b2-a110920cd50e
This commit is contained in:
		
							
								
								
									
										47
									
								
								roles/web-app-chess/templates/Dockerfile.j2
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								roles/web-app-chess/templates/Dockerfile.j2
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,47 @@ | ||||
| # Multi-stage build for castling.club | ||||
| # Stage 1: build | ||||
| FROM node:{{ CHESS_VERSION }} AS build | ||||
|  | ||||
| ARG CHESS_REPO_URL={{ CHESS_REPO_URL }} | ||||
| ARG CHESS_REPO_REF={{ CHESS_REPO_REF }} | ||||
|  | ||||
| RUN apt-get update && apt-get install -y --no-install-recommends \ | ||||
|     git ca-certificates openssl dumb-init python3 build-essential \ | ||||
|  && rm -rf /var/lib/apt/lists/* | ||||
|  | ||||
| WORKDIR /src | ||||
| RUN git clone --depth 1 --branch "${CHESS_REPO_REF}" "${CHESS_REPO_URL}" ./ | ||||
|  | ||||
| # Yarn is preinstalled in Node images via corepack; enable it. | ||||
| RUN corepack enable | ||||
|  | ||||
| # Install deps and build TS | ||||
| RUN yarn install --frozen-lockfile && yarn build | ||||
|  | ||||
| # Stage 2: runtime | ||||
| FROM node:{{ CHESS_VERSION }} | ||||
|  | ||||
| ENV NODE_ENV=production | ||||
| ENV PORT={{ container_port }} | ||||
| WORKDIR /app | ||||
|  | ||||
| # Minimal runtime packages + dumb-init | ||||
| RUN apt-get update && apt-get install -y --no-install-recommends \ | ||||
|     openssl dumb-init postgresql-client \ | ||||
|  && rm -rf /var/lib/apt/lists/* | ||||
|  | ||||
| # Copy built app | ||||
| COPY --from=build /src /app | ||||
|  | ||||
| # Create data dir for signing keys & cache | ||||
| RUN mkdir -p /app/data && chown -R node:node /app | ||||
| VOLUME ["/app/data"] | ||||
|  | ||||
| # Entrypoint script | ||||
| COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh | ||||
| RUN chmod +x /usr/local/bin/docker-entrypoint.sh | ||||
|  | ||||
| USER node | ||||
| EXPOSE {{ container_port }} | ||||
| ENTRYPOINT ["dumb-init", "--"] | ||||
| CMD ["docker-entrypoint.sh"] | ||||
							
								
								
									
										29
									
								
								roles/web-app-chess/templates/docker-compose.yml.j2
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								roles/web-app-chess/templates/docker-compose.yml.j2
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,29 @@ | ||||
| {% include 'roles/docker-compose/templates/base.yml.j2' %} | ||||
|   application: | ||||
|     build: | ||||
|       context: . | ||||
|       dockerfile: Dockerfile | ||||
|       args: | ||||
|         CHESS_REPO_URL: "{{ CHESS_REPO_URL }}" | ||||
|         CHESS_REPO_REF: "{{ CHESS_REPO_REF }}" | ||||
|     image: "castling_custom" | ||||
|     container_name: "{{ CHESS_CONTAINER }}" | ||||
|     hostname: "{{ CHESS_HOSTNAME }}" | ||||
|     environment: | ||||
|       - NODE_ENV=production | ||||
|     ports: | ||||
|       - "127.0.0.1:{{ ports.localhost.http[application_id] }}:{{ container_port }}" | ||||
|     volumes: | ||||
|       - 'data:/app/data' | ||||
|     env_file: | ||||
|       - .env | ||||
| {% include 'roles/docker-container/templates/healthcheck/curl.yml.j2' %} | ||||
| {% include 'roles/docker-container/templates/base.yml.j2' %} | ||||
| {% include 'roles/docker-container/templates/depends_on/dmbs_excl.yml.j2' %} | ||||
| {% include 'roles/docker-container/templates/networks.yml.j2' %} | ||||
|  | ||||
| {% include 'roles/docker-compose/templates/volumes.yml.j2' %} | ||||
|   data: | ||||
|     name: {{ CHESS_DATA_VOLUME }} | ||||
|  | ||||
| {% include 'roles/docker-compose/templates/networks.yml.j2' %} | ||||
							
								
								
									
										27
									
								
								roles/web-app-chess/templates/docker-entrypoint.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								roles/web-app-chess/templates/docker-entrypoint.sh
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | ||||
| #!/usr/bin/env bash | ||||
| set -euo pipefail | ||||
|  | ||||
| APP_KEY_FILE="${APP_KEY_FILE:-/app/data/{{ CHESS_KEY_FILENAME }}}" | ||||
| APP_KEY_PUB="${APP_KEY_FILE}.pub" | ||||
|  | ||||
| # 1) Generate signing key pair if missing | ||||
| if [[ ! -f "${APP_KEY_FILE}" || ! -f "${APP_KEY_PUB}" ]]; then | ||||
|   echo "[chess] generating RSA signing key pair at ${APP_KEY_FILE}" | ||||
|   /app/tools/gen-signing-key.sh "${APP_KEY_FILE}" | ||||
| fi | ||||
|  | ||||
| # 2) Wait for PostgreSQL if env is provided | ||||
| if [[ -n "${PGHOST:-}" ]]; then | ||||
|   echo "[chess] waiting for PostgreSQL at ${PGHOST}:${PGPORT:-5432}..." | ||||
|   until pg_isready -h "${PGHOST}" -p "${PGPORT:-5432}" -U "${PGUSER:-postgres}" >/dev/null 2>&1; do | ||||
|     sleep 1 | ||||
|   done | ||||
| fi | ||||
|  | ||||
| # 3) Run migrations (idempotent) | ||||
| echo "[chess] running migrations" | ||||
| yarn migrate up | ||||
|  | ||||
| # 4) Start app | ||||
| echo "[chess] starting server on port ${PORT:-5080}" | ||||
| exec yarn start | ||||
							
								
								
									
										16
									
								
								roles/web-app-chess/templates/env.j2
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								roles/web-app-chess/templates/env.j2
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,16 @@ | ||||
| # App basics | ||||
| APP_SCHEME="{{ 'https' if WEB_PROTOCOL == 'https' else 'http' }}" | ||||
| APP_DOMAIN="{{ CHESS_HOSTNAME }}" | ||||
| APP_ADMIN_URL="{{ CHESS_ADMIN_URL }}" | ||||
| APP_ADMIN_EMAIL="{{ CHESS_ADMIN_EMAIL }}" | ||||
| APP_KEY_FILE="/app/data/{{ CHESS_KEY_FILENAME }}" | ||||
| APP_HMAC_SECRET="{{ CHESS_HMAC_SECRET }}" | ||||
| NODE_ENV="production" | ||||
| PORT="{{ container_port }}" | ||||
|  | ||||
| # PostgreSQL (libpq envs) | ||||
| PGHOST="{{ database_host }}" | ||||
| PGPORT="{{ database_port }}" | ||||
| PGDATABASE="{{ database_name }}" | ||||
| PGUSER="{{ database_username }}" | ||||
| PGPASSWORD="{{ database_password }}" | ||||
		Reference in New Issue
	
	Block a user