ci(test): Quote 추가해서 도커 실행 #31
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: Deploy 'prod' to Amazon EC2 | |
on: | |
push: | |
branches: | |
- prod | |
jobs: | |
deploy: | |
name: Deploy | |
runs-on: ubuntu-latest | |
environment: prod | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.AWS_REGION_CODE }} | |
- name: Upload to AWS ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v2 | |
- name: Build, tag, and push image to ECR | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
ECR_REPOSITORY: ${{ secrets.AWS_ECR_REPOSITORY }} | |
IMAGE_TAG: ${{ github.sha }} | |
run: | | |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -t $ECR_REGISTRY/$ECR_REPOSITORY:latest ./rest-api | |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest | |
- name: Deploy to EC2 Instance | |
uses: appleboy/[email protected] | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
ECR_REPOSITORY: ${{ secrets.AWS_ECR_REPOSITORY }} | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION_CODE: ${{ secrets.AWS_REGION_CODE }} | |
AWS_S3_BUCKET_NAME: ${{ secrets.AWS_S3_BUCKET_NAME }} | |
DB_HOST: ${{ secrets.DB_HOST }} | |
DB_PORT: ${{ secrets.DB_PORT }} | |
DB_NAME: ${{ secrets.DB_NAME }} | |
DB_USER: ${{ secrets.DB_USER }} | |
DB_PASSWORD: ${{ secrets.DB_PASSWORD }} | |
JWT_SECRET: ${{ secrets.JWT_SECRET }} | |
GOOGLE_EMAIL: ${{ secrets.GOOGLE_EMAIL }} | |
GOOGLE_APP_PASSWORD: ${{ secrets.GOOGLE_APP_PASSWORD }} | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USERNAME }} | |
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} | |
port: ${{ secrets.EC2_SSH_PORT }} | |
envs: ECR_REGISTRY, ECR_REPOSITORY, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION_CODE, AWS_S3_BUCKET_NAME, DB_HOST, DB_PORT, DB_NAME, DB_USER, DB_PASSWORD, JWT_SECRET, GOOGLE_EMAIL, GOOGLE_APP_PASSWORD | |
script: | | |
sudo rm -rf .aws | |
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID | |
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY | |
aws configure set default.region $AWS_REGION_CODE | |
aws configure set default.ouput json | |
docker stop myapp || true | |
docker rm myapp || true | |
aws ecr get-login-password --region $AWS_REGION_CODE | docker login --username AWS --password-stdin $ECR_REGISTRY | |
docker pull $ECR_REGISTRY/$ECR_REPOSITORY:latest | |
docker run -d \ | |
-e AWS_ACCESS_KEY_ID='$AWS_ACCESS_KEY_ID' \ | |
-e AWS_SECRET_ACCESS_KEY='$AWS_SECRET_ACCESS_KEY' \ | |
-e AWS_REGION_CODE='$AWS_REGION_CODE' \ | |
-e AWS_S3_BUCKET_NAME='$AWS_S3_BUCKET_NAME' \ | |
-e DB_HOST='$DB_HOST' \ | |
-e DB_PORT='$DB_PORT' \ | |
-e DB_NAME='$DB_NAME' \ | |
-e DB_USER='$DB_USER' \ | |
-e DB_PASSWORD='$DB_PASSWORD' \ | |
-e JWT_SECRET='$JWT_SECRET' \ | |
-e GOOGLE_EMAIL='$GOOGLE_EMAIL' \ | |
-e GOOGLE_APP_PASSWORD='$GOOGLE_APP_PASSWORD' \ | |
-p 8080:8080 \ | |
--name myapp $ECR_REGISTRY/$ECR_REPOSITORY:latest |