๐จ ๋ถ์ค top3 ์ค์๊ฐ ๋ฐ์ #116
Workflow file for this run
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: Web Application Server - CI/CD | |
on: | |
push: | |
branches: ["main"] | |
pull_request_target: | |
types: [labeled, closed] | |
jobs: | |
# safe tag์ ๋ํ gradlew test && merged์ ๋ํ docker image build and push | |
CI: | |
if: contains(github.event.pull_request.labels.*.name, 'safe') | |
runs-on: ubuntu-20.04 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Create .env | |
shell: bash | |
run: | | |
touch .env | |
echo SECRET_KEY=${{ secrets.SECRET_KEY }} >> .env | |
echo ADMIN_PATH=${{ secrets.ADMIN_PATH }} >> .env | |
echo DEBUG_VALUE=${{ secrets.DEBUG_VALUE }} >> .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=${{ secrets.DATABASE_HOST }} >> .env | |
echo DATABASE_PORT=${{ secrets.DATABASE_PORT }} >> .env | |
cat .env | |
- name: Set up Python 3.8 | |
uses: actions/setup-python@v2 | |
with: | |
python-version: 3.8 | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip3 install -r requirements.txt | |
- name: Run tests | |
run: | | |
python3 manage.py test | |
### Docker Image Build and Push ### | |
- name: Login to Docker Hub | |
if: github.event.pull_request.merged == true | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Set up Docker Buildx | |
if: github.event.pull_request.merged == true | |
uses: docker/setup-buildx-action@v2 | |
- name: Build and push | |
if: github.event.pull_request.merged == true | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }} | |
# closed์ ๋ํ server deploy | |
CD: | |
if: github.event.pull_request.merged == true | |
needs: [CI] | |
runs-on: ubuntu-20.04 | |
steps: | |
### SSH Connect and Docker Image Pull and Container Run | |
- name: Docker Image Pull and Container Run | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
username: ${{ secrets.SSH_USERNAME }} | |
password: ${{ secrets.SSH_PASSWORD }} | |
port: ${{ secrets.SSH_PORT }} | |
script: | | |
docker stop festival2023-was | |
docker rm festival2023-was | |
docker image rm ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }} | |
docker run -d --net festival -v festival-media:/app/media -v festival-static:/app/static -e TZ=Asia/Seoul -p 8000:8000 --name festival2023-was ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }} |