Skip to content

CICD : 도커 캐시 사용해서 빌드 최적화 #55

CICD : 도커 캐시 사용해서 빌드 최적화

CICD : 도커 캐시 사용해서 빌드 최적화 #55

Workflow file for this run

name: Zerozero Server CICD
on:
push:
branches: [ "develop" ]
pull_request:
branches: [ "develop" ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker
uses: docker/login-action@v3
with:
username: ${{secrets.DOCKER_USERNAME}}
password: ${{secrets.DOCKER_ACCESS_TOKEN}}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
dockerfile: Dockerfile
push: true
tags: ${{secrets.DOCKER_USERNAME}}/zerozero:latest
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{secrets.HOST}}
username: ubuntu
key: ${{secrets.PEM_KEY}}
script: |
sudo docker pull ${{secrets.DOCKER_USERNAME}}/zerozero:latest
EXISTING_CONTAINER_ID=$(sudo docker ps -q -f "publish=8080" -f "status=running")
if [ ! -z "$EXISTING_CONTAINER_ID" ]; then
sudo docker stop $EXISTING_CONTAINER_ID
sudo docker rm $EXISTING_CONTAINER_ID
fi
EXISTING_CONTAINER_ID=$(sudo docker ps -q -f "publish=8080" -f "status=exited")
if [ ! -z "$EXISTING_CONTAINER_ID" ]; then
sudo docker rm $EXISTING_CONTAINER_ID
fi
sudo docker rm $(sudo docker ps --filter 'status=exited' -a -q)
sudo docker run -d --log-driver=syslog -p 8080:8080 -e JAVA_OPTS=-Djasypt.encryptor.password=${{secrets.JASYPT_ENCRYPTOR_PASSWORD}} ${{secrets.DOCKER_USERNAME}}/zerozero:latest
sudo docker image prune -a -f