Skip to content

infra : dockerfile 수정 #19

infra : dockerfile 수정

infra : dockerfile 수정 #19

Workflow file for this run

name: production CI&CD to AWS
on:
push:
branches:
- prod
env:
AWS_REGION: ${{ secrets.AWS_REGION }}
S3_BUCKET_NAME: ${{ secrets.S3_BUCKET_NAME }}
CODE_DEPLOY_APPLICATION_NAME: ${{ secrets.PROD_CODE_DEPLOY_APP_NAME }}
CODE_DEPLOY_DEPLOYMENT_GROUP_NAME: ${{secrets.PROD_CODE_DEPLOY_DEPLOYMENT_GROUP_NAME }}
APPLICATION_DIR: src/main/resources
APPLICATION_PROD: ${{ secrets.APPLICATION_PROD }}
permissions:
id-token: write
contents: write
jobs:
build-docker:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
with:
token: ${{ secrets.PRIVATE_TOKEN }}
submodules: true
- name: setup jdk 11
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '11'
cache: 'gradle'
- name: Copy properties
run: echo $APPLICATION_PROD | base64 --decode > $APPLICATION_DIR/application-prod.yml
- name: add permission to gradlew
run: chmod +x ./gradlew
shell: bash
- name: aws configure
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
- name: Login to ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: build docker file and setting deploy files
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ssafsound-prod-repo
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
mkdir scripts
touch scripts/deploy.sh
echo "aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin $ECR_REGISTRY" >> scripts/deploy.sh
echo "docker pull $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> scripts/deploy.sh
echo "docker run -p 8080:8080 -e PROFILE=prod -d --restart always --name ssafsound-api $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> scripts/deploy.sh
- name: upload to s3
env:
IMAGE_TAG: ${{ github.sha }}
run: |
zip -r deploy-$IMAGE_TAG.zip ./scripts appspec.yml
aws s3 cp --region ap-northeast-2 --acl private ./deploy-$IMAGE_TAG.zip s3://$S3_BUCKET_NAME
- name: start deploy
env:
IMAGE_TAG: ${{ github.sha }}
run: |
aws deploy create-deployment --application-name $CODE_DEPLOY_APPLICATION_NAME \
--deployment-config-name CodeDeployDefault.OneAtATime \
--deployment-group-name $CODE_DEPLOY_DEPLOYMENT_GROUP_NAME \
--s3-location bucket=$S3_BUCKET_NAME,bundleType=zip,key=deploy-$IMAGE_TAG.zip