Merge pull request #22 from SQUAD-D/feature#17/image-s3 #89
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
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
name: Deploy Spring boot to Amazon EC2 | |
env: | |
PROJECT_NAME: board | |
permissions: | |
contents: read | |
jobs: | |
deploy: | |
name: SIMPLE-BOARD DEPLOY | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v1 | |
with: | |
java-version: 17 | |
- name: Set Yaml | |
uses: microsoft/variable-substitution@v1 | |
with: | |
files: ./src/main/resources/application-prod.yml | |
env: | |
spring.datasource.url: ${{ secrets.DB_URL }} | |
spring.datasource.username: ${{ secrets.DB_USER_NAME }} | |
spring.datasource.password: ${{ secrets.DB_PASSWORD }} | |
cloud.aws.s3.bucket: ${{ secrets.BUCKET_NAME }} | |
cloud.aws.region.static: ${{ secrets.AWS_REGION }} | |
cloud.aws.credentials.access-key: ${{ secrets.S3_ACCESS }} | |
cloud.aws.credentials.secret-key: ${{ secrets.S3_SECRET }} | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
shell: bash | |
- name: Build with Gradle | |
run: ./gradlew build | |
shell: bash | |
# Docker 이미지 Build | |
- name: docker image build WAS-01 | |
run: docker build -t haechansomg/simple-board:was01 -f ./dockerFile-was01 . | |
- name: docker image build WAS-02 | |
run: docker build -t haechansomg/simple-board2:was02 -f ./dockerFile-was02 . | |
# DockerHub Login | |
- name: docker login | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
# Docker Hub push | |
- name: docker Hub push WAS-01 | |
run: docker push haechansomg/simple-board:was01 | |
# Docker Hub push | |
- name: docker Hub push WAS-02 | |
run: docker push haechansomg/simple-board2:was02 | |
- name: Deploy to server | |
uses: appleboy/[email protected] | |
id: deploy | |
env: | |
COMPOSE: "/home/ubuntu/compose/docker-compose.yml" | |
with: | |
host: ${{ secrets.HOST }} | |
username: ubuntu | |
key: ${{ secrets.KEY }} | |
envs: COMPOSE | |
port: 22 | |
script: | | |
sudo docker-compose -f $COMPOSE down --rmi all | |
sudo docker pull haechansomg/simple-board:was01 | |
sudo docker pull haechansomg/simple-board2:was02 | |
sudo docker-compose -f $COMPOSE up -d | |
sudo docker image prune -f |