feat: CI/CD #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: Deploy to Amazon ECS CI/CD | |
on: | |
push: | |
branches: [ "feat/ec2" ] | |
env: | |
AWS_REGION: ap-northeast-2 | |
jobs: | |
deploy: | |
name: Deploy | |
runs-on: ubuntu-latest | |
environment: develop | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'adopt' | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Copy Secret | |
env: | |
CREATE_SECRET: ${{secrets.DAITSSU_DEV_APPLICATION_YML}} | |
CREATE_SECRET_DIR: src/main/resources | |
CREATE_SECRET_DIR_FILE_NAME: application-dev.yml | |
run: echo $CREATE_SECRET | base64 --decode > $CREATE_SECRET_DIR/$CREATE_SECRET_DIR_FILE_NAME | |
- name: Build with Gradle | |
run: ./gradlew build | |
- 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: ${{ env.AWS_REGION }} | |
- name: Copy JAR to EC2 | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USER_NAME }} | |
key: ${{ secrets.EC2_PRIVATE_KEY }} | |
source: "build/libs/*.jar" | |
target: ${{ secrets.EC2_PATH }} |