Bemyplan Product Deploy #67
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: Bemyplan Product Deploy | |
on: | |
workflow_dispatch: | |
push: | |
branches: [ master ] | |
env: | |
AWS_REGION: ap-northeast-2 # set this to your preferred AWS region, e.g. us-west-1 | |
ECR_REPOSITORY: bemyplan-prod-image # set this to your Amazon ECR repository name | |
ECS_TASK_DEFINITION: task-definition-prod.json # set this to the path to your Amazon ECS task definition | |
CONTAINER_NAME: bemyplan-prod-container # set this to the name of the container in the | |
ECS_SERVICE: bemyplan-prod-svc # set this to your Amazon ECS service name | |
ECS_CLUSTER: bemyplan-prod-cluster # set this to your Amazon ECS cluster name | |
jobs: | |
build-gradle: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '11' | |
distribution: 'temurin' | |
- name: Build with Gradle | |
run: chmod +x ./gradlew && ./gradlew :applications:app-bemyplan:build | |
- name: Upload jar artifact | |
uses: actions/upload-artifact@v1 | |
with: | |
name: app | |
path: applications/app-bemyplan/build/libs | |
- name: Upload dockerfile | |
uses: actions/upload-artifact@v1 | |
with: | |
name: app | |
path: Dockerfile | |
- name: Upload aws | |
uses: actions/upload-artifact@v1 | |
with: | |
name: aws | |
path: .aws/task-definition-prod.json | |
publish-ecr: | |
needs: build-gradle | |
runs-on: ubuntu-latest | |
outputs: | |
image: ${{ steps.build-image.outputs.image }} | |
steps: | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_DEPLOY }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_DEPLOY }} | |
aws-region: ${{ env.AWS_REGION }} | |
mask-aws-account-id: 'no' | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: download jar artifact | |
uses: actions/download-artifact@v1 | |
with: | |
name: app | |
- name: Build, tag, and push image to Amazon ECR | |
id: build-image | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
IMAGE_TAG: ${{ github.sha }} | |
run: | | |
cd app && docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . | |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" | |
ecs-run: | |
needs: publish-ecr | |
runs-on: ubuntu-latest | |
steps: | |
- name: print | |
run: echo ${{ needs.publish-ecr.outputs.image }} | |
- name: download aws artifact | |
uses: actions/download-artifact@v1 | |
with: | |
name: aws | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_DEPLOY }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_DEPLOY }} | |
aws-region: ${{ env.AWS_REGION }} | |
- name: ECS task definition | |
id: task-def | |
uses: aws-actions/amazon-ecs-render-task-definition@v1 | |
with: | |
task-definition: aws/${{ env.ECS_TASK_DEFINITION }} | |
container-name: ${{ env.CONTAINER_NAME }} | |
image: ${{ needs.publish-ecr.outputs.image }} | |
- name: Deploy Amazon ECS task definition | |
uses: aws-actions/amazon-ecs-deploy-task-definition@v1 | |
with: | |
task-definition: ${{ steps.task-def.outputs.task-definition }} | |
service: ${{ env.ECS_SERVICE }} | |
cluster: ${{ env.ECS_CLUSTER }} | |
wait-for-service-stability: true |