배포하려는 가상 instance 서버를 runner 와 연결해야한다.
repository → setting → action → runner → new self-host runner
디렉토리 생성
member
디렉토리를 하나 더 추가해줬다.mkdir actions-runner && cd actions-runner
mkdir member && cd member
curl -o actions-runner-linux-x64-2.304.0.tar.gz -L https://github.com/actions/runner/releases/download/v2.304.0/actions-runner-linux-x64-2.304.0.tar.gz
echo "292e8770bdeafca135c2c06cd5426f9dda49a775568f45fcc25cc2b576afc12f actions-runner-linux-x64-2.304.0.tar.gz" | shasum -a 256 -c
tar xzf ./actions-runner-linux-x64-2.304.0.tar.gz
./config.sh --url https://github.com/BAEKER-230522/Member --token A3RPC4EMMH2OAOHLKMA2S2LENOEHQ
Enter
2번, 라벨을 설정하는 3번째 질문엔 label-sp
를 입력하고,Y
, Enter
를 입력하면 설정아 완료된다.label-sp
는 나중에 CD 파일에서 설정할 라벨명이다../run.sh
로 언제든지 원하는 runner 와 연결할 수 있게된다.⚠️ 아래 명령어로 데몬모드로 repostiroy 와 연결할 수 있다.
nohup ./run.sh &
CD 워크플로우
의 deploy
파트에 작성하는 디렉토리에 생성해주면 된다.docker stop [이미지]
docker rm [이미지]
docker image rm -f choidaekuk/[이미지]
docker run \
-p [서버]:[도커] \
-d -e TZ=Asia/Seoul \
-e JAVA_OPTS=-Djasypt.encryptor.password=[암호키] \
-e JAVA_ACTIVE=-Dspring.profiles.active=prod \
--name=[이미지] \
--restart always \
choidaekuk/[이미지]
name: DockerCD
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: 저장소 Checkout
uses: actions/checkout@v2
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: temurin
- name: 스프링부트 애플리케이션 빌드 # (1)
run: ./gradlew build -Pjasypt.encryptor.password=${{secrets.JASYPT_ENCRYPTOR_PASSWORD}}
- name: Docker Hub 로그인 # (2)
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: 도커 이미지 빌드 # (3)
run: docker build --build-arg JAR_FILE=build/libs/*.jar -t ${{ secrets.DOCKERHUB_IMAGE_NAME }} .
- name: tag 설정 # (4)
run: docker tag ${{ secrets.DOCKERHUB_IMAGE_NAME }} ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE_NAME }}
- name: Docker Hub 퍼블리시 # (5)
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE_NAME }}
deploy:
needs: build
name: Deploy
runs-on: [ self-hosted, label-sp ]
steps:
- name: deploy run
run: |
sh /home/ubuntu/dep/docker/run.sh
FROM openjdk:17
ARG JAR_FILE=build/libs/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["sh", "-c", "java ${JAVA_OPTS} ${JAVA_ACTIVE} -jar /app.jar"]
./run.sh
# 데몬
nohup ./run.sh &
./run.sh
로 연결하면된다.docker ps
docker logs -f {컨테이너 번호}