Skip to content

Feat: Sending an authentication email to user #71

Feat: Sending an authentication email to user

Feat: Sending an authentication email to user #71

Workflow file for this run

name: Build and Push Docker Image to AWS ECR
on:
push:
branches: [develop]
pull_request:
branches: [develop] # develop 브랜치에 push/pr 했을 때 workflow를 trigger함.
jobs:
build-and-push-image:
runs-on: ubuntu-latest
steps:
# 코드 내려받기
- name: Checkout source code
uses: actions/checkout@v2
# 자바 버전 세팅
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: '17'
distribution: 'temurin'
# 환경 변수 설정
- name: Set up Environment
working-directory: ./src/main
run: |
cd ./resources
touch ./application.yml
echo "${{ secrets.APPLICATION_YML }}" | base64 --decode >> application.yml
# 빌드 권한 부여
- name: Grant execute permission for gradlew
run: chmod +x gradlew
# 빌드
- name: Build with Gradle
run: ./gradlew clean build -x test
# 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 ECR 로그인
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
# Image 빌드 및 ECR에 Push 수행
- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY_NAME }}
run: |
docker build --platform=linux/amd64 -t $ECR_REGISTRY/$ECR_REPOSITORY .
docker push $ECR_REGISTRY/$ECR_REPOSITORY
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" >> scripts/deploy.sh
echo "docker rm -f codedeploy" >> scripts/deploy.sh
echo "docker rmi $ECR_REGISTRY/$ECR_REPOSITORY" >> scripts/deploy.sh
echo "docker run -d --name codedeploy -p 8080:8080 --restart always $ECR_REGISTRY/$ECR_REPOSITORY" >> scripts/deploy.sh
# zip 파일로 압축
- name: zip file
run: zip -r fullcar.zip ./scripts ./src/main/resources/application.yml ./appspec.yml ./build/libs/*.jar
# S3에 업로드
- name: Upload to S3
run:
aws s3 cp --region ap-northeast-2 ./fullcar.zip s3://fullcar-build/deploy/
# Deploy 시작
- name: Deploy with AWS codeDeploy
run: |
aws deploy create-deployment \
--application-name fullcar-codedeploy \
--deployment-config-name CodeDeployDefault.OneAtATime \
--deployment-group-name GROUP \
--s3-location bucket=fullcar-build,bundleType=zip,key=deploy/fullcar.zip