main.yml version 구체화 #18
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 | |
steps: | |
- name: Check out the repository | |
uses: actions/checkout@v2 | |
- name: Set up Python 3.10 | |
uses: actions/setup-python@v2 | |
with: | |
python-version: 3.10.10 | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
- name: Lint with flake8 | |
run: | | |
pip install flake8 | |
# stop the build if there are Python syntax errors or undefined names | |
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | |
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | |
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | |
- name: Build Docker image | |
run: docker build . --file Dockerfile --tag fastapi_app:latest | |
- name: Push Docker image to Docker Hub | |
run: | | |
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin | |
docker tag fastapi_app:latest ${{ secrets.DOCKER_USERNAME }}/fastapi_app:latest | |
docker push ${{ secrets.DOCKER_USERNAME }}/fastapi_app:latest | |
- name: Deploy to server | |
run: | | |
ssh -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} << 'EOF' | |
docker pull ${{ secrets.DOCKER_USERNAME }}/fastapi_app:latest | |
docker stop fastapi_app || true | |
docker rm fastapi_app || true | |
docker run -d --name fastapi_app -p 80:80 ${{ secrets.DOCKER_USERNAME }}/fastapi_app:latest | |
EOF | |