Skip to content

Workflow file for this run

name: Deploy FullStackApp to AWS
on:
push:
branches:
- feature/actions-pipeline
env:
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }}
AWS_REGION: ap-northeast-2
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- 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: ${{ env.AWS_REGION }}
- name: Login to Docker Hub
run: echo $DOCKER_HUB_PASSWORD | docker login -u $DOCKER_HUB_USERNAME --password-stdin
# Frontend 빌드 및 S3 배포
# - name: Build and deploy Frontend
# run: |
# cd frontend
# npm ci
# npm run build
# aws s3 sync build/ s3://${{ secrets.S3_BUCKET }} --delete
# aws cloudfront create-invalidation --distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }} --paths "/*"
# Backend, AI, Crawling 이미지 빌드 및 푸시
- name: Build and push Docker images
run: |
docker build -t $DOCKER_HUB_USERNAME/backend:latest ./backend
docker build -t $DOCKER_HUB_USERNAME/ai:latest ./ai
docker build -t $DOCKER_HUB_USERNAME/crawling:latest ./crawling
docker push $DOCKER_HUB_USERNAME/backend:latest
docker push $DOCKER_HUB_USERNAME/ai:latest
docker push $DOCKER_HUB_USERNAME/crawling:latest
# Backend 서비스 배포 (AWS Systems Manager 사용)
- name: Deploy Backend services
run: |
aws ssm send-command \
--instance-ids ${{ secrets.BACKEND_EC2_INSTANCE_ID }} \
--document-name "AWS-RunShellScript" \
--parameters '{
"commands": [
"docker pull ${{ env.DOCKER_HUB_USERNAME }}/backend:latest",
"docker pull ${{ env.DOCKER_HUB_USERNAME }}/ai:latest",
"docker stop backend ai || true",
"docker rm backend ai || true",
"docker network create backend-network || true",
"docker run -d --name ai --network backend-network -p 5000:5000 ${{ env.DOCKER_HUB_USERNAME }}/ai:latest",
"docker run -d --name backend --network backend-network -p 8080:8080 ${{ env.DOCKER_HUB_USERNAME }}/backend:latest"
]
}'
# Crawling 서비스 배포 (SSH를 통한 직접 배포)
- name: Deploy Crawling service
env:
EC2_KEY: ${{ secrets.EC2_KEY }}
run: |
echo "$EC2_KEY" > /tmp/ec2_key
chmod 600 /tmp/ec2_key
ssh -o StrictHostKeyChecking=no -i /tmp/ec2_key ec2-user@${{ secrets.CRAWLING_EC2_HOST }} '
docker pull ${{ env.DOCKER_HUB_USERNAME }}/crawling:latest
docker stop crawling || true
docker rm crawling || true
docker run -d --name crawling -p 5001:5001 ${{ env.DOCKER_HUB_USERNAME }}/crawling:latest
'
rm /tmp/ec2_key
- name: Cleanup
if: always()
run: |
docker logout
rm -f /tmp/ec2_key