Skip to content

Merge pull request #23 from LINE-NOW/JongbeomLee623-patch-2 #4

Merge pull request #23 from LINE-NOW/JongbeomLee623-patch-2

Merge pull request #23 from LINE-NOW/JongbeomLee623-patch-2 #4

Workflow file for this run

name: Web Application CI/CD Pipeline
on:
push:
branches:
- main
pull_request:
types: [closed]
jobs:
CI:
runs-on: ubuntu-latest
services:
db:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: ${{ secrets.DATABASE_USER_PASSWORD }}
MYSQL_DATABASE: ${{ secrets.DATABASE_NAME }}
MYSQL_USER: ${{ secrets.DATABASE_USER }}
MYSQL_PASSWORD: ${{ secrets.DATABASE_USER_PASSWORD }}
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping --silent"
--health-interval=10s
--health-timeout=5s
--health-retries=3
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Create .env file
run: |
echo "SECRET_KEY=${{ secrets.SECRET_KEY }}" >> .env
echo "DEBUG=${{ secrets.DEBUG }}" >> .env
echo "DJANGO_DEPLOY=${{ secrets.DJANGO_DEPLOY }}" >> .env
echo "DATABASE_ENGINE=${{ secrets.DATABASE_ENGINE }}" >> .env
echo "DATABASE_NAME=${{ secrets.DATABASE_NAME }}" >> .env
echo "DATABASE_USER=${{ secrets.DATABASE_USER }}" >> .env
echo "DATABASE_USER_PASSWORD=${{ secrets.DATABASE_USER_PASSWORD }}" >> .env
echo "DATABASE_HOST=127.0.0.1" >> .env # DB는 로컬에서 실행됨
echo "DATABASE_PORT=3306" >> .env
cat .env
- name: Set up Python 3.12
uses: actions/setup-python@v3
with:
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run migrations and tests
run: |
python manage.py makemigrations
python manage.py migrate
python manage.py test
build_and_push:
needs: CI
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}:latest
deploy:
needs: build_and_push
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
steps:
- name: SSH into server and pull Docker image
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
port: ${{ secrets.SSH_PORT }}
script: |
cd /path/to/project
docker-compose down
docker-compose pull
docker-compose up -d
- name: Collect static files
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
port: ${{ secrets.SSH_PORT }}
script: |
docker exec -it linenow-was python manage.py collectstatic --noinput