Skip to content

Backend CD

Backend CD #57

Workflow file for this run

name: Backend CD
on:
workflow_dispatch:
pull_request:
branches:
- develop
paths:
- backend/**
jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: backend
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build Gradle
run: ./gradlew clean bootJar
- name: DockerHub Login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Docker Build
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/spaceme-dev:latest .
- name: Docker Push
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/spaceme-dev:latest
deploy:
runs-on: self-hosted
needs: build
defaults:
run:
working-directory: backend
steps:
- name: Docker Pull & Run
run: |
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/spaceme-dev:latest
docker stop server || true
docker container prune -f
docker run -d --name server -p 8080:8080 \
--env-file ./.env \
${{ secrets.DOCKERHUB_USERNAME }}/spaceme-dev:latest
docker rmi $(docker images -f "dangling=true" -q)