fix api docs #24
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: Docker | |
on: | |
push: | |
branches: [backend] | |
jobs: | |
deploy-main: | |
runs-on: ubuntu-latest | |
if: github.event_name == 'push' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
# 도커 이미지에 env 파일 포함 | |
- name: Create .env file | |
run: | | |
echo "DB_HOST=${{ secrets.DB_HOST }}" >> ./.env | |
echo "DB_USER=${{ secrets.DB_USER }}" >> ./.env | |
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> ./.env | |
echo "DB_DBNAME=${{ secrets.DB_DBNAME }}" >> ./.env | |
echo "DB_PORT=${{ secrets.DB_PORT }}" >> ./.env | |
echo "CLIENT_ID=${{ secrets.CLIENT_ID }}" >> ./.env | |
echo "CLIENT_SECRET=${{ secrets.CLIENT_SECRET }}" >> ./.env | |
echo "CALLBACK_URL=${{ secrets.CALLBACK_URL }}" >> ./.env | |
echo "JWT_SECRET_KEY=${{ secrets.JWT_SECRET_KEY }}" >> ./.env | |
# 도커 메타 | |
- name: Docker meta | |
id: docker_meta | |
uses: crazy-max/ghaction-docker-meta@v1 | |
with: | |
images: nowgnues/capstone-back | |
tag-semver: | | |
{{version}} | |
{{major}}.{{minor}} | |
tag-custom: main | |
# 도커 빌드 관련 셋업 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
# 내 도커허브 로그인 | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
# 도커이미지 빌드하고 허브로 푸쉬 | |
- name: Build and push | |
uses: docker/build-push-action@v3 | |
with: | |
context: . | |
file: ./Dockerfile | |
platforms: | | |
linux/amd64 | |
push: true | |
tags: ${{ steps.docker_meta.outputs.tags }} | |
labels: ${{ steps.docker_meta.outputs.labels }} | |
# Github Action 의 IP 불러옴 | |
- name: Get Github Actions IP | |
id: ip | |
uses: haythem/[email protected] | |
# AWS 접근 인증 | |
#- name: Configure AWS Credentials | |
# uses: aws-actions/configure-aws-credentials@v1 | |
# with: | |
# aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
# aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
# aws-region: ap-northeast-2 | |
# AWS CLI로 EC2의 보안 그룹에 현재 Github Actions의 IP를 등록하여 SSH 접근이 가능하도록 해줍니다. | |
#- name: Add Github Actions IP to Security group | |
# run: | | |
# aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 | |
# EC2에 Docker 이미지 배포 | |
- name: Deploy to EC2 | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.EC2_HOST }} # EC2 인스턴스의 호스트 주소 | |
username: ${{ secrets.EC2_USERNAME }} # EC2 인스턴스의 사용자 이름 | |
key: ${{ secrets.EC2_SSH_KEY }} # EC2 인스턴스에 접속하기 위한 SSH 키 | |
script: | | |
# Docker 이미지 가져오기 | |
sudo docker-compose -f /home/docker-compose/capstone/docker-compose.yml down --rmi all || true | |
sudo docker pull nowgnues/capstone-back:main | |
sudo docker-compose -f /home/docker-compose/capstone/docker-compose.yml up -d | |
# 인바운드 규칙 삭제 | |
#- name: Remove Github Actions IP From Security Group | |
# run: | | |
# aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 |