Merge remote-tracking branch 'origin/main' into main #54
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: Spring-Boot-Idea-rush-Amazon EC2 | |
on: | |
push: | |
branches: | |
- main | |
env: | |
AWS_REGION: ap-northeast-2 | |
ECR_REGISTRY: ${{ secrets.AWS_ECR_ADDRESS }} | |
ECR_REPOSITORY: idea-rush | |
IMAGE_TAG: latest | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
with: | |
token: ${{ secrets.ACTION_TOKEN }} | |
submodules: true | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v1 | |
with: | |
java-version: 17 | |
- name: Grant execute permission for gradlew | |
run: chmod +x ./gradlew | |
shell: bash | |
- name: Build with Gradle | |
run: ./gradlew build | |
shell: bash | |
- name: Login to AWS ECR | |
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 Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Build and Push Docker image | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
ECR_REPOSITORY: idea-rush | |
IMAGE_TAG: latest | |
run: | | |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . | |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
- name: Execute Server Init Script | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.WAS_HOST }} | |
username: ${{ secrets.WAS_USER }} | |
key: ${{ secrets.WAS_PASSWORD }} | |
script: | | |
docker stop ${{ env.ECR_REPOSITORY }} | |
docker rm ${{ env.ECR_REPOSITORY }} | |
docker pull ${{ env.ECR_REGISTRY }}:${{ env.IMAGE_TAG }} | |
docker run -d -p 8080:8080 --name idea-rush ${{ env.ECR_REGISTRY }} |