Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 94 additions & 12 deletions .github/workflows/gradle-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,28 @@ on:
pull_request:
branches: [ master ]


env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
REMOTE_PATH: /opt/dockerfiles/radio
GHCR_USER: splayfery
TAGS: latest

jobs:
build-and-deploy:
build-and-publish:

runs-on: ubuntu-latest

permissions:
contents: read
packages: write
attestations: write
id-token: write

steps:
- uses: actions/checkout@v3
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set up Coretto 21
uses: actions/setup-java@v3
Expand All @@ -42,6 +53,67 @@ jobs:
- name: Build with Gradle
run: ./gradlew build --parallel --no-daemon --configuration-cache

- name: Set up QEMU (for ARM emulation)
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
install: true
driver: docker-container

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Cleanup old latest images in GHCR
uses: actions/delete-package-versions@v5
continue-on-error: true
with:
package-name: radio
package-type: container
min-versions-to-keep: 1

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: ${{ env.TAGS }}

- name: Build and push multi-arch Docker image
id: push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64

- name: Generate artifact attestation
uses: actions/attest-build-provenance@v2
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true

start-service:

runs-on: ubuntu-latest
needs: build-and-publish

permissions:
contents: read
packages: write

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Install SSH Key
uses: shimataro/ssh-key-action@v2
with:
Expand All @@ -66,15 +138,25 @@ jobs:
env:
SSH_USER: ${{ secrets.USERNAME }}
SSH_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_HOST: ${{ secrets.HOST }}

- name: Deploy Gradle Artifacts
run: rsync -avz /home/runner/work/Radio/Radio/build/libs/ ${{ secrets.USERNAME }}@${{ secrets.HOST }}:/opt/dockerfiles/radio

- name: Sync Docker Configuration
run: rsync -avz --include="Dockerfile" --include="docker-compose.yaml" --exclude="*" . ${{ secrets.USERNAME }}@${{ secrets.HOST }}:/opt/dockerfiles/radio
SSH_HOST: ${{ secrets.HOST }}

- name: Rebuild container
- name: Set lowercase IMAGE_NAME
run: echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV

- name: Deploy and Restart Container
run: |
ssh staging docker compose -f /opt/dockerfiles/radio/docker-compose.yaml down
ssh staging docker compose -f /opt/dockerfiles/radio/docker-compose.yaml up -d
ssh staging "
echo '${{ secrets.GHCR_TOKEN }}' | docker login ghcr.io -u ${{ env.GHCR_USER }} --password-stdin &&

# Stop running container
docker compose -f ${REMOTE_PATH}/docker-compose.yaml down || true &&

# Pull latest image
docker pull ${REGISTRY}/${IMAGE_NAME}:${{ env.TAGS }} &&

# Remove unused old images
docker image prune -af &&

# Start new container
docker compose -f ${REMOTE_PATH}/docker-compose.yaml up -d
"
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM amazoncorretto:21

RUN mkdir /bot
COPY radio-1.0-SNAPSHOT.jar /bot
COPY build/libs/radio-1.0-SNAPSHOT.jar /bot

ENTRYPOINT ["java", "-jar", "/bot/radio-1.0-SNAPSHOT.jar"]
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dependencies {
api libs.dev.lavalink.youtube.common
}

group = 'de.splayfer'
group = 'de.splayfunityde'
version = '1.0-SNAPSHOT'
description = 'radio'
java.sourceCompatibility = JavaVersion.VERSION_21
Expand Down
4 changes: 1 addition & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
services:
radio:
build:
context: .
dockerfile: Dockerfile
image: ghcr.io/splayfunityde/radio:latest
restart: always
volumes:
- /opt/dockerfiles/radio:/bot
Expand Down