add files for hosting with docker
This commit is contained in:
21
Dockerfile.updater
Normal file
21
Dockerfile.updater
Normal file
@@ -0,0 +1,21 @@
|
||||
FROM alpine:latest
|
||||
|
||||
RUN apk add --no-cache git docker-cli curl
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Clone the repo
|
||||
RUN git clone https://git.nauen-it.de/tobias/Pokemon-Type-Quiz.git .
|
||||
|
||||
# Install node and npm
|
||||
RUN apk add --no-cache nodejs npm
|
||||
|
||||
# Install dependencies and build
|
||||
RUN npm install && npm run build
|
||||
|
||||
# Script to rebuild on changes
|
||||
COPY rebuild_docker.sh /rebuild_docker.sh
|
||||
RUN chmod +x /rebuild_docker.sh
|
||||
|
||||
# Initial build
|
||||
CMD ["/rebuild_docker.sh"]
|
||||
26
docker-compose.yml
Normal file
26
docker-compose.yml
Normal file
@@ -0,0 +1,26 @@
|
||||
version: '1.0'
|
||||
|
||||
networks:
|
||||
frontend:
|
||||
external: true
|
||||
|
||||
services:
|
||||
web:
|
||||
image: nginx:latest
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- '/hdd/poketypes:/usr/share/nginx/html:ro'
|
||||
networks:
|
||||
- frontend
|
||||
|
||||
updater:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.updater
|
||||
volumes:
|
||||
- /hdd/poketypes:/dist
|
||||
environment:
|
||||
- REPO_URL=https://git.nauen-it.de/tobias/Pokemon-Type-Quiz.git
|
||||
- BRANCH=main
|
||||
restart: unless-stopped
|
||||
|
||||
40
rebuild_docker.sh
Executable file
40
rebuild_docker.sh
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/bin/sh
|
||||
|
||||
REPO_URL="${REPO_URL:-https://github.com/YOUR_USERNAME/YOUR_REPO.git}"
|
||||
BRANCH="${BRANCH:-main}"
|
||||
POLL_INTERVAL="${POLL_INTERVAL:-3600}"
|
||||
|
||||
echo "Starting updater for $REPO_URL (branch: $BRANCH)"
|
||||
|
||||
# Build initially
|
||||
cd /app
|
||||
npm install
|
||||
npm run build
|
||||
|
||||
# Copy to shared volume
|
||||
cp -r /app/dist/* /dist/
|
||||
|
||||
echo "Initial build complete"
|
||||
|
||||
# Poll for updates
|
||||
while true; do
|
||||
sleep "$POLL_INTERVAL"
|
||||
|
||||
echo "Checking for updates..."
|
||||
git fetch origin "$BRANCH"
|
||||
|
||||
LOCAL=$(git rev-parse HEAD)
|
||||
REMOTE=$(git rev-parse origin/"$BRANCH")
|
||||
|
||||
if [ "$LOCAL" != "$REMOTE" ]; then
|
||||
echo "New changes detected! Rebuilding..."
|
||||
|
||||
git pull origin "$BRANCH"
|
||||
npm run build
|
||||
cp -r /app/dist/* /dist/
|
||||
|
||||
echo "Done!"
|
||||
else
|
||||
echo "No changes"
|
||||
fi
|
||||
done
|
||||
Reference in New Issue
Block a user