Add Docker and deployment configurations for development and production environments
Some checks failed
Deploy Production (crewsportswear.com) / deploy (push) Failing after 5m18s
Some checks failed
Deploy Production (crewsportswear.com) / deploy (push) Failing after 5m18s
This commit is contained in:
145
.gitea/workflows/deploy.yml
Normal file
145
.gitea/workflows/deploy.yml
Normal file
@@ -0,0 +1,145 @@
|
||||
name: Deploy Production (crewsportswear.com)
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- master
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: catthehacker/ubuntu:act-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
shell: sh
|
||||
run: |
|
||||
git clone $GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git /workspace/repo
|
||||
cd /workspace/repo
|
||||
git checkout $GITHUB_REF_NAME
|
||||
|
||||
- name: Build Docker image
|
||||
shell: sh
|
||||
run: |
|
||||
cd /workspace/repo
|
||||
docker build -t crewsportswear:latest .
|
||||
docker save crewsportswear:latest | gzip > crewsportswear.tar.gz
|
||||
|
||||
- name: Setup SSH
|
||||
shell: sh
|
||||
env:
|
||||
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
|
||||
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
||||
run: |
|
||||
mkdir -p ~/.ssh
|
||||
chmod 700 ~/.ssh
|
||||
echo "$DEPLOY_SSH_KEY" > ~/.ssh/id_ed25519
|
||||
chmod 600 ~/.ssh/id_ed25519
|
||||
ssh-keyscan -H "$DEPLOY_HOST" >> ~/.ssh/known_hosts
|
||||
|
||||
- name: Upload image and compose
|
||||
shell: sh
|
||||
env:
|
||||
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
|
||||
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
||||
run: |
|
||||
scp -i ~/.ssh/id_ed25519 \
|
||||
/workspace/repo/crewsportswear.tar.gz \
|
||||
/workspace/repo/docker-compose.prod.yml \
|
||||
${DEPLOY_USER}@${DEPLOY_HOST}:/tmp/
|
||||
|
||||
- name: Deploy on server
|
||||
shell: sh
|
||||
env:
|
||||
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
|
||||
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
||||
|
||||
run: |
|
||||
ssh -i ~/.ssh/id_ed25519 $DEPLOY_USER@$DEPLOY_HOST << 'EOF'
|
||||
set -e
|
||||
|
||||
DEPLOY_DIR="/var/www/crewsportswear"
|
||||
sudo mkdir -p "$DEPLOY_DIR"
|
||||
sudo chown $USER:$USER "$DEPLOY_DIR"
|
||||
|
||||
echo "Stopping dev environment"
|
||||
DEV_DIR="/var/www/apps/crewsportswear_dev"
|
||||
if [ -d "$DEV_DIR" ]; then
|
||||
cd "$DEV_DIR"
|
||||
docker compose down || true
|
||||
cd -
|
||||
echo "Dev environment stopped"
|
||||
echo "Copying .env from dev to production"
|
||||
if [ -f "$DEV_DIR/.env" ]; then
|
||||
cp "$DEV_DIR/.env" "$DEPLOY_DIR/.env"
|
||||
echo ".env file copied from dev to production"
|
||||
else
|
||||
echo "No .env file found in dev directory"
|
||||
fi else
|
||||
echo "No dev environment found"
|
||||
fi
|
||||
|
||||
echo "Loading image"
|
||||
docker load < /tmp/crewsportswear.tar.gz
|
||||
|
||||
echo "Removing dev images and old crewsportswear images"
|
||||
docker images | grep "crewsportswear:dev" | awk '{print $3}' | xargs -r docker rmi -f || true
|
||||
docker images | grep crewsportswear | grep -v "$(docker images crewsportswear:latest -q)" | awk '{print $3}' | xargs -r docker rmi -f || true
|
||||
|
||||
echo "Updating compose file"
|
||||
cp /tmp/docker-compose.prod.yml "$DEPLOY_DIR/docker-compose.yml"
|
||||
|
||||
cd "$DEPLOY_DIR"
|
||||
|
||||
echo "Checking .env file"
|
||||
if [ ! -f .env ]; then
|
||||
echo ".env file not found at $DEPLOY_DIR/.env"
|
||||
echo "Please create it first with required variables:"
|
||||
echo " - DB_*, PROD_PRIVATE, IMAGES_URL, UPLOAD_URL"
|
||||
echo " - MAIL_*, CAPTCHA_*, ANALYTICS_*"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Fixing .env permissions"
|
||||
sudo chown $USER:$USER .env
|
||||
sudo chmod 600 .env
|
||||
|
||||
echo "Ensure networks"
|
||||
docker network inspect traefik-public >/dev/null 2>&1 || \
|
||||
docker network create traefik-public
|
||||
docker network inspect crew-app-net >/dev/null 2>&1 || \
|
||||
docker network create crew-app-net
|
||||
|
||||
echo "Starting containers (env vars from .env file)"
|
||||
docker compose up -d
|
||||
|
||||
echo "Waiting for app container"
|
||||
sleep 15
|
||||
|
||||
if docker ps --format '{{.Names}}' | grep -q crewsportswear_app; then
|
||||
echo "Clearing and rebuilding config cache"
|
||||
docker compose exec -T app php artisan config:clear
|
||||
docker compose exec -T app php artisan config:cache
|
||||
else
|
||||
echo "App container not running"
|
||||
docker compose logs
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Cleanup"
|
||||
rm -f /tmp/crewsportswear.tar.gz /tmp/docker-compose.prod.yml
|
||||
|
||||
echo "Aggressive Docker cleanup to reclaim space"
|
||||
docker image prune -af --filter "until=24h" || true
|
||||
docker container prune -f || true
|
||||
docker volume prune -f || true
|
||||
docker builder prune -af --filter "until=48h" || true
|
||||
echo "Docker space usage:"
|
||||
docker system df
|
||||
|
||||
echo "Production deployment completed!"
|
||||
echo "Application available at: https://crewsportswear.com"
|
||||
EOF
|
||||
Reference in New Issue
Block a user