100 lines
3.7 KiB
YAML
100 lines
3.7 KiB
YAML
name: Build and Push Docker Image
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- develop
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
build-and-push:
|
|
runs-on: docker
|
|
|
|
steps:
|
|
- name: Install Docker CLI
|
|
run: |
|
|
wget -q https://download.docker.com/linux/static/stable/x86_64/docker-25.0.3.tgz
|
|
tar xzf docker-25.0.3.tgz --strip-components=1 -C /usr/local/bin docker/docker
|
|
rm docker-25.0.3.tgz
|
|
docker --version
|
|
|
|
- name: Clone repository
|
|
run: |
|
|
apk add --no-cache git || apt-get update && apt-get install -y git
|
|
cd /workspace/szmyt151
|
|
rm -rf szmyt151 || true
|
|
git clone --depth 1 --branch ${GITHUB_REF##*/} https://git.szmyt151.pl/szmyt151/szmyt151.git
|
|
cd szmyt151
|
|
ls -la
|
|
|
|
- name: Build Docker images
|
|
run: |
|
|
cd /workspace/szmyt151/szmyt151
|
|
# Build web image
|
|
docker build -t registry.szmyt151.pl/registryuser/szmyt151-web:latest .
|
|
docker tag registry.szmyt151.pl/registryuser/szmyt151-web:latest registry.szmyt151.pl/registryuser/szmyt151-web:$GITHUB_SHA
|
|
# Build webmcp image
|
|
docker build -f Dockerfile.webmcp -t registry.szmyt151.pl/registryuser/szmyt151-webmcp:latest .
|
|
docker tag registry.szmyt151.pl/registryuser/szmyt151-webmcp:latest registry.szmyt151.pl/registryuser/szmyt151-webmcp:$GITHUB_SHA
|
|
|
|
- name: Login to Docker Registry
|
|
run: |
|
|
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login registry.szmyt151.pl -u ${{ secrets.REGISTRY_USERNAME }} --password-stdin
|
|
|
|
- name: Push Docker images
|
|
run: |
|
|
docker push registry.szmyt151.pl/registryuser/szmyt151-web:latest
|
|
docker push registry.szmyt151.pl/registryuser/szmyt151-web:$GITHUB_SHA
|
|
docker push registry.szmyt151.pl/registryuser/szmyt151-webmcp:latest
|
|
docker push registry.szmyt151.pl/registryuser/szmyt151-webmcp:$GITHUB_SHA
|
|
|
|
- name: Cleanup
|
|
if: always()
|
|
run: |
|
|
docker logout registry.szmyt151.pl || true
|
|
|
|
- name: List all containers (verify deployment)
|
|
run: |
|
|
echo "=== All containers on host ==="
|
|
docker ps -a
|
|
echo "=== Container logs ==="
|
|
docker logs szmyt151-web --tail=5 || true
|
|
docker logs szmyt151-webmcp --tail=5 || true
|
|
|
|
- name: Deploy containers
|
|
run: |
|
|
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login registry.szmyt151.pl -u ${{ secrets.REGISTRY_USERNAME }} --password-stdin
|
|
|
|
# Pull latest images
|
|
docker pull registry.szmyt151.pl/registryuser/szmyt151-web:latest
|
|
docker pull registry.szmyt151.pl/registryuser/szmyt151-webmcp:latest
|
|
|
|
# Stop and remove existing containers
|
|
docker stop szmyt151-web szmyt151-webmcp || true
|
|
docker rm szmyt151-web szmyt151-webmcp || true
|
|
|
|
# Start web container
|
|
docker run -d \
|
|
--name szmyt151-web \
|
|
-p 8080:80 \
|
|
-v szmyt151-web-vendor:/var/www/html/vendor \
|
|
--restart unless-stopped \
|
|
registry.szmyt151.pl/registryuser/szmyt151-web:latest
|
|
|
|
# Start webmcp container
|
|
docker run -d \
|
|
--name szmyt151-webmcp \
|
|
-p 3000:3000 \
|
|
--restart unless-stopped \
|
|
--link szmyt151-web:web \
|
|
-e CONTACT_API_URL=http://web:80/api/contact.php \
|
|
-e NODE_ENV=production \
|
|
registry.szmyt151.pl/registryuser/szmyt151-webmcp:latest
|
|
|
|
docker logout registry.szmyt151.pl
|
|
echo "Containers deployed successfully"
|