chore: 빌드 과정중에 yml이 포함되도록 기능 추가 #10
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
name: Java CICD with Gradle | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
permissions: | |
contents: read | |
jobs: | |
build-docker-image: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Set YML | |
run: | | |
mkdir -p bucketback-api/src/main/resources | |
echo "${{ secrets.APPLICATION_YML }}" | base64 --decode > bucketback-api/src/main/resources/application.yml | |
echo "${{ secrets.APPLICATION_API_YML }}" | base64 --decode > bucketback-api/src/main/resources/application-api.yml | |
find bucketback-api/src | |
mkdir -p bucketback-domain/src/main/resources | |
echo "${{ secrets.APPLICATION_DOMAIN_YML }}" | base64 --decode > bucketback-domain/src/main/resources/application-domain.yml | |
find bucketback-domain/src | |
mkdir -p bucketback-infrastructure/src/main/resources | |
echo "${{ secrets.APPLICATION_INFRA_YML }}" | base64 --decode > bucketback-infrastructure/src/main/resources/application-infra.yml | |
find bucketback-infrastructure/src | |
- name: Build with Gradle | |
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 | |
with: | |
arguments: clean bootJar | |
- name: docker image build | |
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/lime-image . | |
- name: docker login | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: docker Hub push | |
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/lime-image | |
run-docker-image-on-server: | |
needs: build-docker-image | |
runs-on: self-hosted | |
steps: | |
- name: docker pull | |
run: sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/lime-image | |
- name: docker stop container | |
run: sudo docker stop $(sudo docker ps -q) 2>/dev/null || true | |
- name: docker run new container | |
run: sudo docker run --name lime-image --rm -d -p 8080:8080 ${{ secrets.DOCKERHUB_USERNAME }}/lime-image | |
- name: delete old docker image | |
run: sudo docker system prune -f |