Skip to content

์„œ๋ฒ„์—์„œ ๋ฉ”์‹œ์ง€ ์†ก์‹  ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ๋Š” ๋ฉ”์‹œ์ง€๋ฅผ ์ „๋‹ฌํ•˜์ง€ ์•Š๋Š” ๊ธฐ๋Šฅ ๊ตฌํ˜„ #53

์„œ๋ฒ„์—์„œ ๋ฉ”์‹œ์ง€ ์†ก์‹  ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ๋Š” ๋ฉ”์‹œ์ง€๋ฅผ ์ „๋‹ฌํ•˜์ง€ ์•Š๋Š” ๊ธฐ๋Šฅ ๊ตฌํ˜„

์„œ๋ฒ„์—์„œ ๋ฉ”์‹œ์ง€ ์†ก์‹  ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ๋Š” ๋ฉ”์‹œ์ง€๋ฅผ ์ „๋‹ฌํ•˜์ง€ ์•Š๋Š” ๊ธฐ๋Šฅ ๊ตฌํ˜„ #53

Workflow file for this run

name: Java CI with Gradle
on:
push:
branches: [ "dev" ]
pull_request:
branches: [ "dev" ]
permissions:
contents: read
jobs:
build-docker-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'
- 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 }}/github-actions-demo .
# 4. DockerHub ๋กœ๊ทธ์ธ
- name: docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
# 5. Docker Hub ์ด๋ฏธ์ง€ ํ‘ธ์‹œ
- name: docker Hub push
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/github-actions-demo
run-docker-image-on-ec2:
# build-docker-image (์œ„)๊ณผ์ •์ด ์™„๋ฃŒ๋˜์–ด์•ผ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.
needs: build-docker-image
runs-on: self-hosted
steps:
# 1. ์ตœ์‹  ์ด๋ฏธ์ง€๋ฅผ ํ’€๋ฐ›์Šต๋‹ˆ๋‹ค
- name: docker pull
run: sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/github-actions-demo
# 2. ๊ธฐ์กด์˜ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ค‘์ง€์‹œํ‚ต๋‹ˆ๋‹ค
- name: docker stop container
run: sudo docker stop $(sudo docker ps -q) 2>/dev/null || true
# 3. ์ตœ์‹  ์ด๋ฏธ์ง€๋ฅผ ์ปจํ…Œ์ด๋„ˆํ™”ํ•˜์—ฌ ์‹คํ–‰์‹œํ‚ต๋‹ˆ๋‹ค
- name: docker run new container
run: sudo docker run --name github-actions-demo --rm -d -p 8080:8080 ${{ secrets.DOCKERHUB_USERNAME }}/github-actions-demo
# 4. ๋ฏธ์‚ฌ์šฉ ์ด๋ฏธ์ง€๋ฅผ ์ •๋ฆฌํ•ฉ๋‹ˆ๋‹ค
- name: delete old docker image
run: sudo docker system prune -f