-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
82 additions
and
6 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## 작업사항 | ||
- 내용을 적어주세요. | ||
|
||
## 변경로직 | ||
- 내용을 적어주세요. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
name: Build And Deploy for Api Server | ||
|
||
on: | ||
push: | ||
branches: ['dev'] | ||
|
||
env: | ||
ACTIVE_PROFILE: "dev" | ||
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | ||
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} | ||
DOCKERHUB_API_IMAGE_NAME: ${{ secrets.DOCKERHUB_API_IMAGE_NAME }} | ||
|
||
jobs: | ||
build-and-push: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
java-version: [ 17 ] | ||
outputs: | ||
image_tag: ${{ steps.image_tag.outputs.image_tag }} | ||
|
||
steps: | ||
- name: Check Out The Repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Java | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: ${{ matrix.java-version }} | ||
distribution: 'corretto' | ||
|
||
- name: Grant execute permission for gradlew | ||
run: chmod +x ./gradlew | ||
|
||
- name: Execute Gradle build | ||
run: | | ||
./gradlew build --no-daemon | ||
- name: Make image tag | ||
run: echo "IMAGE_TAG=$ACTIVE_PROFILE-${GITHUB_SHA::7}" >> $GITHUB_ENV | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Build docker image and push image | ||
run: | | ||
docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_TOKEN | ||
docker build --build-arg PROFILE=$ACTIVE_PROFILE -t $DOCKERHUB_USERNAME/$DOCKERHUB_API_IMAGE_NAME:${{env.IMAGE_TAG}} . | ||
docker push $DOCKERHUB_USERNAME/$DOCKERHUB_API_IMAGE_NAME:${{env.IMAGE_TAG}} | ||
- name: Pass Image tag value | ||
id: image_tag | ||
run: echo "image_tag=${{env.IMAGE_TAG}}" >> $GITHUB_OUTPUT | ||
|
||
deploy: | ||
needs: build-and-push | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Set image tag from Output | ||
run: echo "IMAGE_TAG=${{ needs.build-and-push.outputs.image_tag }}" >> $GITHUB_ENV | ||
|
||
- name: SSH remote and Run Docker container | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.REMOTE_IP }} | ||
username: ${{ secrets.REMOTE_USERNAME }} | ||
key: ${{ secrets.REMOTE_SSH_KEY }} | ||
port: ${{ secrets.REMOTE_SSH_PORT }} | ||
script: | | ||
sudo touch .env | ||
echo "${{ secrets.ENV_VARS }}" | sudo tee .env > /dev/null | ||
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_API_IMAGE_NAME }}:${{env.IMAGE_TAG}} | ||
docker stop $(docker ps -a -q) | ||
docker run --restart=unless-stopped -d -p 8080:8080 --env-file .env --add-host=host.docker.internal:host-gateway ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_API_IMAGE_NAME }}:${{env.IMAGE_TAG}} | ||
docker rm $(docker ps --filter 'status=exited' -a -q) | ||
docker image prune -a -f |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,7 @@ | ||
package com.testcar.car; | ||
|
||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
@SpringBootTest | ||
class CarApplicationTests { | ||
|
||
@Test | ||
void contextLoads() {} | ||
} | ||
class CarApplicationTests {} |