추가: 배포 방식 변경 #37
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 | |
# Trigger the workflow on push events to the main branch | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Check out the code from the repository | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
# Step 2: Set up Docker Buildx | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
# Step 3: Configure AWS credentials for the workflow | |
- 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 | |
# Step 4: Log in to Amazon ECR (Elastic Container Registry) | |
- name: Login to Amazon ECR | |
run: | | |
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws | |
# Step 5: Build and push Docker image to Amazon ECR | |
- name: Build and push Docker image | |
id: build-image | |
run: | | |
IMAGE_TAG=$(date +%Y%m%d%H%M) | |
docker build -t public.ecr.aws/h7p2f6d8/ticats_ai:$IMAGE_TAG . | |
docker tag public.ecr.aws/h7p2f6d8/ticats_ai:$IMAGE_TAG public.ecr.aws/h7p2f6d8/ticats_ai:latest | |
docker push public.ecr.aws/h7p2f6d8/ticats_ai:$IMAGE_TAG | |
docker push public.ecr.aws/h7p2f6d8/ticats_ai:latest | |
env: | |
DATABASE_URL: ${{ secrets.DATABASE_URL }} | |
# Step 6: Deploy to EC2 instance | |
- name: Run SSH Command | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.EC2_INSTANCE_IP }} | |
username: ec2-user | |
key: ${{ secrets.EC2_SSH_KEY }} | |
port: 22 | |
script: | | |
export DATABASE_URL=${{ secrets.DATABASE_URL }} | |
docker pull public.ecr.aws/h7p2f6d8/ticats_ai:latest | |
echo ls | |
docker-compose down | |
docker-compose up -d | |
# Step 6: Deploy to EC2 instance | |
- name: Run SSH Command | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.EC2_INSTANCE_IP }} | |
username: ec2-user | |
key: ${{ secrets.EC2_SSH_KEY }} | |
port: 22 | |
script: | | |
sudo docker stop ticats_ai || true | |
sudo docker rm ticats_ai || true | |
sudo docker image rm public.ecr.aws/h7p2f6d8/ticats_ai:latest || true | |
docker pull public.ecr.aws/h7p2f6d8/ticats_ai:latest | |
sudo docker run -d -p 8000:8000 --name ticats_ai -e DATABASE_URL="${{ secrets.DATABASE_URL }}" public.ecr.aws/h7p2f6d8/ticats_ai:latest |