feat: add deploy server feature on pipeline #36
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: Build and Push to ECR | |
on: | |
push: | |
branches: | |
- staging # Change this to your desired branch | |
env: | |
REGION: ap-northeast-2 # Seoul | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'temurin' | |
java-version: '17' | |
check-latest: true | |
- name: make application.yml | |
run: | | |
mkdir ./src/main/resources | |
cd ./src/main/resources | |
touch ./application.yml | |
echo "${{ secrets.YML }}" > ./application.yml | |
shell: bash | |
- name: make application-dev.yml | |
run: | | |
cd ./src/main/resources | |
touch ./application-dev.yml | |
echo "${{ secrets.YML_STAGING }}" > ./application-dev.yml | |
cat ./application-dev.yml | |
shell: bash | |
- name: Setup Gradle 7.6 | |
uses: gradle/gradle-build-action@v2 | |
with: | |
gradle-version: 7.6 | |
- name: Gradle Caching | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
- name: Build Spring Boot application | |
run: gradle 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.REGION }} | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Build and tag Docker image | |
run: | | |
docker build -t ${{ secrets.ECR_REGISTRY }}/dev:latest . | |
- name: Push Docker image to ECR | |
run: | | |
docker push ${{ secrets.ECR_REGISTRY }}/dev:latest | |
deploy: | |
needs: build-and-push | |
runs-on: ubuntu-latest | |
steps: | |
- name: Deploy on Staging Server | |
uses: appleboy/ssh-action@v0.1.10 | |
with: | |
host: ${{ secrets.AWS_STAGING }} | |
username: ${{ secrets.AWS_SSH_USERNAME }} | |
key: ${{ secrets.AWS_SSH_KEY }} | |
script_stop: true | |
script: | | |
cd /app | |
docker-compose pull | |
docker-compose up -d |