104 lines
3.2 KiB
YAML
104 lines
3.2 KiB
YAML
name: Build and Deploy
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Install Docker CLI
|
|
run: |
|
|
apt-get update
|
|
apt-get install -y ca-certificates curl gnupg
|
|
install -m 0755 -d /etc/apt/keyrings
|
|
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
|
|
chmod a+r /etc/apt/keyrings/docker.gpg
|
|
|
|
echo \
|
|
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
|
|
bullseye stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
|
|
|
|
apt-get update
|
|
apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v2
|
|
|
|
- name: Login to Harbor Registry
|
|
uses: docker/login-action@v2
|
|
with:
|
|
registry: harbor.galpodlipnik.com
|
|
username: ${{ secrets.HARBOR_USERNAME }}
|
|
password: ${{ secrets.HARBOR_PASSWORD }}
|
|
|
|
- name: Build and push Backend image
|
|
uses: docker/build-push-action@v4
|
|
with:
|
|
context: ./backend
|
|
push: true
|
|
tags: harbor.galpodlipnik.com/chat-app/backend:latest
|
|
|
|
- name: Build and push Frontend image
|
|
uses: docker/build-push-action@v4
|
|
with:
|
|
context: ./frontend
|
|
push: true
|
|
tags: harbor.galpodlipnik.com/chat-app/frontend:latest
|
|
|
|
- name: Create docker-compose.yml
|
|
run: |
|
|
cat > docker-compose.yml << 'EOL'
|
|
version: '3.8'
|
|
services:
|
|
backend:
|
|
image: harbor.galpodlipnik.com/chat-app/backend:latest
|
|
restart: always
|
|
env_file:
|
|
- ./backend/.env
|
|
ports:
|
|
- "3000:3000"
|
|
networks:
|
|
- chat-network
|
|
|
|
frontend:
|
|
image: harbor.galpodlipnik.com/chat-app/frontend:latest
|
|
restart: always
|
|
ports:
|
|
- "80:80"
|
|
depends_on:
|
|
- backend
|
|
networks:
|
|
- chat-network
|
|
|
|
networks:
|
|
chat-network:
|
|
driver: bridge
|
|
EOL
|
|
|
|
- name: Deploy with SSH
|
|
uses: appleboy/ssh-action@master
|
|
with:
|
|
host: ${{ secrets.DEPLOY_HOST }}
|
|
username: ${{ secrets.DEPLOY_USERNAME }}
|
|
key: ${{ secrets.DEPLOY_SSH_KEY }}
|
|
script: |
|
|
mkdir -p ~/services/chat-app
|
|
cd ~/services/chat-app
|
|
|
|
# Copy docker-compose.yml to server
|
|
echo "${{ github.workspace }}/docker-compose.yml" > docker-compose.yml
|
|
|
|
# Copy environment file if needed
|
|
# This assumes .env file is in the repository
|
|
echo "${{ secrets.ENV_CONTENT }}" > .env
|
|
|
|
# Pull latest images and deploy
|
|
docker compose pull
|
|
docker compose down
|
|
docker compose up -d |