Merge pull request #54 from Fill-ENERGY/refactor/#49 #34
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
# This workflow uses actions that are not certified by GitHub. | |
# They are provided by a third-party and are governed by | |
# separate terms of service, privacy policy, and support | |
name: Java CI with Gradle | |
on: | |
push: | |
branches: [ "develop" ] | |
# pull_request: | |
# branches: [ "main" ] | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
# permissions: | |
# contents: read | |
steps: | |
# - uses: actions/checkout@v4 | |
- name: Checkout | |
uses: actions/checkout@v3 | |
#setting jdk | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v2 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
#setting yml | |
- name: make application.yml | |
run: | | |
mkdir -p src/main/resources | |
echo "${{ secrets.APPLICATION_YML }}" > src/main/resources/application.yml | |
#gradlew chmod | |
- name: Grant execute permission for gradlew | |
run: chmod +x ./gradlew | |
#spring Boot Build | |
- name: Spring Boot Build | |
run: ./gradlew clean build -x test | |
#----------------- Docker -------- | |
#Docker Image build | |
- name: Docker Image Build | |
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGENAME }} . | |
# DockerHub Login | |
- name: Docker Hub Login | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
# Docker Hub push | |
- name: docker Hub push | |
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGENAME }} | |
#---------EC2---------- | |
#AWS EC2 Server Connect & Docken 명령어 실행 | |
- name: AWS EC2 Connection | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USERNAME }} | |
password: ${{ secrets.EC2_PASSWORD }} | |
port: ${{ secrets.EC2_SSH_PORT }} | |
timeout: 60s | |
script: | | |
CONTAINER_NAME=$(echo "${{ secrets.DOCKERHUB_IMAGENAME }}" | sed 's/[^a-zA-Z0-9_.-]/_/g') | |
sudo docker stop $CONTAINER_NAME || true | |
sudo docker rm $CONTAINER_NAME || true | |
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGENAME }} | |
sudo docker run -d -p 8080:8080 --name $CONTAINER_NAME -e TZ=Asia/Seoul ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGENAME }} |