Merge pull request #102 from SWM-Flash/integration #73
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 | |
on: | |
push: | |
branches: | |
- develop | |
env: | |
ECR_REGISTRY: ${{ secrets.AWS_ECR_REGISTRY }} | |
ECR_REPOSITORY: ${{ secrets.AWS_DEV_ECR_REPOSITORY }} | |
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }} | |
jobs: | |
build_and_push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: checkout code | |
uses: actions/checkout@v2 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v2 | |
with: | |
distribution: 'temurin' | |
java-version: '17' | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Cache Gradle packages | |
uses: actions/cache@v2 | |
with: | |
path: ~/.gradle/caches | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
- name: Build with Gradle | |
run: ./gradlew clean build -x test | |
- 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 | |
- name: Sign in to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v2 | |
- name: Build and push Docker image to Amazon ECR | |
run: | | |
docker build -t $ECR_REPOSITORY:latest . | |
docker tag $ECR_REPOSITORY:latest $ECR_REGISTRY/$ECR_REPOSITORY:latest | |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest | |
- name: Create Dockerrun.aws.json file using ECR image | |
run: | | |
echo '{ | |
"AWSEBDockerrunVersion": "1", | |
"Image": { | |
"Name": "'$ECR_REGISTRY'/'$ECR_REPOSITORY':latest", | |
"Update": "true" | |
}, | |
"Ports": [ | |
{ | |
"ContainerPort": "8080" | |
} | |
] | |
}' > Dockerrun.aws.json | |
- name: Upload Dockerrun.aws.json file to S3 | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: ap-northeast-2 | |
run: | | |
aws s3 cp Dockerrun.aws.json s3://$AWS_S3_BUCKET/dev/Dockerrun-${{ github.sha }}.aws.json | |
- name: Continuous Deploy to Elastic Beanstalk | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: ap-northeast-2 | |
run: | | |
aws elasticbeanstalk create-application-version --application-name flash-application-dev --version-label ${{ github.sha }} --source-bundle S3Bucket=$AWS_S3_BUCKET,S3Key="dev/Dockerrun-${{ github.sha }}.aws.json" | |
aws elasticbeanstalk update-environment --application-name flash-application-dev --environment-name Flash-application-dev-env-1 --version-label ${{ github.sha }} |