Skip to content

test: Gardle, Docker 캐싱을 위한 Feature/#121 test2 (#130) #33

test: Gardle, Docker 캐싱을 위한 Feature/#121 test2 (#130)

test: Gardle, Docker 캐싱을 위한 Feature/#121 test2 (#130) #33

Workflow file for this run

name: backend-push
on:
push:
branches: [ "main", "develop", "feature/#121" ]
paths:
- 'server/**'
jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: ./server
permissions:
contents: read
steps:
- name: CheckOut
uses: actions/checkout@v4
with:
token: ${{secrets.CONFIG_SUBMODULE_TOKEN}}
submodules: true
- 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: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Test with Gradle Wrapper
run: ./gradlew test
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Set up Docker BuildX
uses: docker/setup-buildx-action@v3
- name: Build and push
run: |
docker buildx build --platform linux/arm64 --cache-from=type=registry,ref=${{ secrets.DOCKER_USERNAME }}/haengdong-backend-dev:cache \
--cache-to=type=registry,ref=${{ secrets.DOCKER_USERNAME }}/haengdong-backend-dev:cache,mode=max \
-t ${{ secrets.DOCKER_USERNAME }}/haengdong-backend-dev --push .
deploy:
needs: build
runs-on: self-hosted
steps:
- name: Docker remove
run: |
CONTAINER_IDS=$(sudo docker ps -qa)
if [ -n "$CONTAINER_IDS" ]; then
sudo docker rm -f $CONTAINER_IDS
else
echo "No running containers found."
fi
- name: Docker Image pull
run: sudo docker pull ${{ secrets.DOCKER_USERNAME }}/haengdong-backend-dev
- name: Docker run
run: sudo docker run -d -p 8080:8080 --name haengdong-backend-dev haengdong/haengdong-backend-dev