This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI/CD Pipeline | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
services: | |
docker: | |
image: docker:20.10.16 | |
options: --privileged | |
ports: | |
- 3000:3000 | |
- 4000:4000 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Install Docker Compose | |
run: | | |
sudo curl -L "https://github.com/docker/compose/releases/download/v2.18.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose | |
sudo chmod +x /usr/local/bin/docker-compose | |
docker-compose --version | |
- name: Log in to DockerHub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build and push app image | |
run: | | |
docker-compose -f docker-compose.yml build | |
docker-compose -f docker-compose.yml up -d | |
- name: Push Docker images | |
run: | | |
docker tag blog-app-app:latest ${{ secrets.DOCKER_USERNAME }}/blog-app-app:latest | |
docker tag blog-app-server:latest ${{ secrets.DOCKER_USERNAME }}/blog-app-server:latest | |
docker push ${{ secrets.DOCKER_USERNAME }}/blog-app-app:latest | |
docker push ${{ secrets.DOCKER_USERNAME }}/blog-app-server:latest | |
- name: Deploy to production | |
run: | | |
ssh -o StrictHostKeyChecking=no [email protected] "cd /path/to/app && docker-compose down && docker-compose pull && docker-compose up -d" |