podman compose, etc.
This commit is contained in:
+51
-34
@@ -1,50 +1,67 @@
|
||||
---
|
||||
services:
|
||||
app:
|
||||
build: .
|
||||
spaces:
|
||||
build: ./web
|
||||
container_name: spaces
|
||||
ports:
|
||||
- "2025:2025"
|
||||
- "2025:2025" # Standard HTTP port for the web server
|
||||
volumes:
|
||||
# Mounts the project code into the container.
|
||||
# This makes git pulls faster after the first run.
|
||||
- ./web:/var/www/html
|
||||
environment:
|
||||
# --- Git Settings ---
|
||||
# ⚠️ Use a secure Personal Access Token (PAT) for the URL
|
||||
- GIT_REPO_URL=https://${GITHUB_USER}:${GITHUB_PAT}@github.com/${GITHUB_USER}/${SPACES_REPO}.git
|
||||
- GIT_BRANCH=main
|
||||
|
||||
# --- Database Connection Settings (for your PHP app) ---
|
||||
- DB_HOST=db
|
||||
- DB_DATABASE=mydatabase
|
||||
- DB_USER=myuser
|
||||
- DB_PASSWORD=mypassword
|
||||
|
||||
# --- Backup Script Settings ---
|
||||
# These credentials are used by mysqldump inside the container
|
||||
- MARIADB_USER=${DB_USER}
|
||||
- MARIADB_PASSWORD=${DB_PASSWORD}
|
||||
- MARIADB_DATABASE=${DB_DATABASE}
|
||||
- MARIADB_HOST=db # The service name from this compose file
|
||||
depends_on:
|
||||
- db # Ensures the 'db' container starts before the 'app' container
|
||||
- spaces_api
|
||||
|
||||
db:
|
||||
image: mariadb:latest
|
||||
spaces_api:
|
||||
build: ./api
|
||||
container_name: spaces_api
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "7476:7476"
|
||||
volumes:
|
||||
- spaces_api_logs:/app/logs # Persistent volume for logs
|
||||
depends_on:
|
||||
spaces_db:
|
||||
condition: service_healthy
|
||||
environment:
|
||||
# Pass DB credentials to the Go API
|
||||
- VIPER_DBUSER=vintage
|
||||
- VIPER_DBPASS=changeme
|
||||
- VIPER_DBNAME=vintagecoding
|
||||
- VIPER_DBHOST=spaces_db
|
||||
|
||||
spaces_api_tester:
|
||||
build: ./api
|
||||
container_name: spaces_api_tester
|
||||
depends_on:
|
||||
spaces_db:
|
||||
condition: service_healthy
|
||||
environment:
|
||||
- VIPER_DBUSER=vintage
|
||||
- VIPER_DBPASS=changeme
|
||||
- VIPER_DBNAME=vintagecoding_test
|
||||
- VIPER_DBHOST=spaces_db
|
||||
- VIPER_DBPORT=3306
|
||||
command: ["go", "test", "-v"]
|
||||
|
||||
spaces_db:
|
||||
image: docker.io/mariadb:latest
|
||||
container_name: spaces_db
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 3
|
||||
volumes:
|
||||
# Persists database data on the host machine
|
||||
- db_data:/var/lib/mysql
|
||||
- spaces_db_data:/var/lib/mysql
|
||||
environment:
|
||||
- MARIADB_ROOT_PASSWORD=supersecretrootpassword
|
||||
- MARIADB_DATABASE=mydatabase
|
||||
- MARIADB_USER=myuser
|
||||
- MARIADB_PASSWORD=mypassword
|
||||
- MARIADB_ROOT_PASSWORD=QuaxlyQueen5012!
|
||||
- MARIADB_DATABASE=vintagecoding
|
||||
- MARIADB_USER=vintage
|
||||
- MARIADB_PASSWORD=changeme
|
||||
- MARIADB_EXTRA_DATABASES=vintagecoding_test
|
||||
ports:
|
||||
# Optional: Expose DB port to host for debugging with a GUI client
|
||||
- "3306:3306"
|
||||
|
||||
volumes:
|
||||
db_data: # Defines the named volume for the database
|
||||
spaces_db_data:
|
||||
spaces_api_logs:
|
||||
|
||||
+1
-23
@@ -1,28 +1,6 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# --- Shutdown Handler ---
|
||||
# This function will be called when the container receives a shutdown signal
|
||||
cleanup() {
|
||||
echo "SIGTERM received, initiating backup..."
|
||||
/usr/local/bin/backup.sh # Execute the backup script
|
||||
echo "Backup script finished. Exiting."
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Trap the SIGTERM signal (sent by 'podman-compose down') and call the cleanup function
|
||||
trap 'cleanup' SIGTERM
|
||||
|
||||
# --- Startup Logic ---
|
||||
# Check if the target directory is a git repo. If not, clone it.
|
||||
if [ ! -d "/var/www/html/.git" ]; then
|
||||
echo "No git repository found. Cloning..."
|
||||
# Clone the specified branch of the repository
|
||||
git clone --branch ${GIT_BRANCH} ${GIT_REPO_URL} .
|
||||
else
|
||||
echo "Git repository found. Pulling latest changes..."
|
||||
git pull origin ${GIT_BRANCH}
|
||||
fi
|
||||
composer install
|
||||
|
||||
echo "Starting PHP built-in web server..."
|
||||
# Use 'exec' to replace the script process with the PHP server process.
|
||||
|
||||
Reference in New Issue
Block a user