merge #3
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 will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time | |
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven | |
# 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 | |
# documentation. | |
name: JAVA CI with Maven | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '21' | |
distribution: 'temurin' | |
cache: maven | |
- name: Build with Maven | |
run: mvn -B package --file pom.xml | |
- name: Cache Maven packages | |
uses: actions/cache@v1 | |
with: | |
path: ~/.m2 | |
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} | |
restore-keys: ${{ runner.os }}-m2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: login | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build and push Docker image | |
env: | |
IMAGE_NAME: parkseol/front-server | |
TAG: latest | |
run: | | |
docker build -t $IMAGE_NAME:$TAG . | |
docker push $IMAGE_NAME:$TAG | |
deploy1: | |
runs-on: ubuntu-latest | |
needs: build-and-push | |
steps: | |
- name: Deploy to Front Server 1 | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.SERVER_HOST }} | |
username: ${{ secrets.SERVER_USER }} | |
key: ${{ secrets.SERVER_SSH_KEY }} | |
script: | | |
docker pull parkseol/front-server:latest | |
docker stop front-server-1 || true | |
docker rm front-server-1 || true | |
docker run -d --name front-server-1 --network api_network -p 8081:8081 -e SPRING_PROFILES_ACTIVE=prod parkseol/front-server:latest | |
deploy2: | |
runs-on: ubuntu-latest | |
needs: deploy1 | |
steps: | |
- name: Deploy to Front Server 2 | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.SERVER_HOST }} | |
username: ${{ secrets.SERVER_USER }} | |
key: ${{ secrets.SERVER_SSH_KEY }} | |
script: | | |
docker pull parkseol/front-server:latest | |
docker stop front-server-2 || true | |
docker rm front-server-2 || true | |
docker run -d --name front-server-2 --network api_network -p 8082:8082 -e SPRING_PROFILES_ACTIVE=prod2 parkseol/front-server:latest |