junhao/CICD Workflow #5
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: CD Pipelines | |
on: | |
pull_request: | |
branches: | |
- staging | |
- main | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Make envfile | |
uses: SpicyPizza/create-envfile@v2.0 | |
with: | |
DOCKERHUB_REPO: jjlim159 | |
POSTGRES_HOST: ${{ secrets.POSTGRES_HOST }} | |
POSTGRES_PORT: ${{ secrets.POSTGRES_PORT }} | |
POSTGRES_USER: ${{ secrets.POSTGRES_USER }} | |
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }} | |
POSTGRES_MULTIPLE_DATABASES: users,tournaments,matchmaking,elo-ranking | |
POSTGRES_URL: jdbc:postgresql://${{ secrets.POSTGRES_HOST }}:${{ secrets.POSTGRES_PORT }}/${{ secrets.POSTGRES_DB }} | |
SPRING_PROFILES_ACTIVE: docker | |
- name: Move .env file to backend directory | |
run: mv .env backend/.env | |
- name: Downloading docker-compose | |
uses: KengoTODA/actions-setup-docker-compose@v1 | |
with: | |
version: '2.14.2' | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Push Docker images | |
run: | | |
docker-compose -f backend/docker-compose.yml build | |
- name: Deploy using Docker Compose | |
env: | |
POSTGRES_HOST: ${{ secrets.POSTGRES_HOST }} | |
POSTGRES_PORT: ${{ secrets.POSTGRES_PORT }} | |
POSTGRES_USER: ${{ secrets.POSTGRES_USER }} | |
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }} | |
run: | | |
docker-compose -f backend/docker-compose.yml push |