Skip to content

Commit

Permalink
feat: cd 구축 (#67)
Browse files Browse the repository at this point in the history
github workflow code 작성
docker file 작성
 #66
  • Loading branch information
wcorn authored Apr 22, 2024
1 parent 57f590b commit e038fc1
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
85 changes: 85 additions & 0 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: CD

on:
workflow_run:
workflows: [CI]
types:
- completed

env:
DOCKER_IMAGE: ghcr.io/${{ github.actor }}/dear
VERSION: ${{ github.sha }}
NAME: dear

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@v3
with:
token: ${{ secrets.ACTION_TOKEN }}
submodules: recursive

- name: Setup docker buildx
id: buildx
uses: docker/setup-buildx-action@v1

- name: Cache docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ env.VERSION }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to ghcr
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- 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 with Gradle
run: |
chmod +x gradlew
./gradlew build -x test
- name: web docker build and push
run: |
docker build -t ${{ env.DOCKER_IMAGE }} .
docker push ${{ env.DOCKER_IMAGE }}
deploy:
needs: build
name: Deploy
runs-on: [ self-hosted, dear ]
steps:
- name: Login to ghcr
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Docker run
run: |
docker stop ${{ env.NAME }} && docker rm ${{ env.NAME }} && docker rmi ${{ env.DOCKER_IMAGE }}
docker run -d -p 8090:8090 --name ${{ env.NAME }} --restart always ${{ env.DOCKER_IMAGE }}:latest
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM openjdk:17
ARG JAR_FILE=build/libs/*.jar
COPY ${JAR_FILE} app.jar
EXPOSE 8090
ENTRYPOINT ["sh", "-c", "java -jar -Dspring.profiles.active=dev /app.jar"]

0 comments on commit e038fc1

Please sign in to comment.