Initial pipeline
This commit is contained in:
38
.gitea/workflows/build.yml
Normal file
38
.gitea/workflows/build.yml
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
name: Build Org Backend
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
schedule:
|
||||||
|
- cron: "0 0 * * *"
|
||||||
|
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: build-site
|
||||||
|
env:
|
||||||
|
APP_HOME: /home/zaine/master-folder/projects/java_projects/org_backend
|
||||||
|
SERVICE_NAME: org-backend.service
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Java
|
||||||
|
uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
distribution: temurin
|
||||||
|
java-version: "17"
|
||||||
|
|
||||||
|
- name: Verify toolchain
|
||||||
|
run: |
|
||||||
|
java -version
|
||||||
|
mvn -version
|
||||||
|
|
||||||
|
- name: Build and test
|
||||||
|
run: mvn -B clean verify
|
||||||
|
|
||||||
|
- name: Deploy jar and restart service
|
||||||
|
run: ./scripts/deploy-systemd.sh
|
||||||
12
README.md
12
README.md
@@ -8,3 +8,15 @@ This repository contains the source code and documentation for all of my APIs. I
|
|||||||
|
|
||||||
The repository is organised into the following main directories:
|
The repository is organised into the following main directories:
|
||||||
|
|
||||||
|
# Deployment
|
||||||
|
|
||||||
|
The main branch build is controlled by `.gitea/workflows/build.yml`. On a
|
||||||
|
successful build it packages the Spring Boot jar, installs the project-owned
|
||||||
|
`misc/org-backend.service` unit into systemd, reloads systemd, enables the
|
||||||
|
service, and restarts it.
|
||||||
|
|
||||||
|
The service runs the stable build artifact at:
|
||||||
|
|
||||||
|
```text
|
||||||
|
/home/zaine/master-folder/projects/java_projects/org_backend/target/org-backend.jar
|
||||||
|
```
|
||||||
|
|||||||
22
misc/org-backend.service
Normal file
22
misc/org-backend.service
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Org Backend Spring Boot App
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
User=zaine
|
||||||
|
Group=zaine
|
||||||
|
Environment=SPRING_PROFILES_ACTIVE=prod
|
||||||
|
|
||||||
|
WorkingDirectory=/home/zaine/master-folder/projects/java_projects/org_backend
|
||||||
|
|
||||||
|
ExecStart=/usr/bin/java -jar /home/zaine/master-folder/projects/java_projects/org_backend/target/org-backend.jar
|
||||||
|
|
||||||
|
SuccessExitStatus=143
|
||||||
|
Restart=always
|
||||||
|
RestartSec=5
|
||||||
|
|
||||||
|
# Optional: limit memory
|
||||||
|
# Environment="JAVA_OPTS=-Xms256m -Xmx1g"
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
1
pom.xml
1
pom.xml
@@ -88,6 +88,7 @@
|
|||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
<finalName>org-backend</finalName>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
|||||||
34
scripts/deploy-systemd.sh
Executable file
34
scripts/deploy-systemd.sh
Executable file
@@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
APP_HOME="${APP_HOME:-/home/zaine/master-folder/projects/java_projects/org_backend}"
|
||||||
|
SERVICE_NAME="${SERVICE_NAME:-org-backend.service}"
|
||||||
|
|
||||||
|
SOURCE_DIR="$(pwd)"
|
||||||
|
SOURCE_JAR="${SOURCE_DIR}/target/org-backend.jar"
|
||||||
|
APP_TARGET_DIR="${APP_HOME}/target"
|
||||||
|
APP_JAR="${APP_TARGET_DIR}/org-backend.jar"
|
||||||
|
SOURCE_SERVICE="${SOURCE_DIR}/misc/${SERVICE_NAME}"
|
||||||
|
SYSTEMD_SERVICE="/etc/systemd/system/${SERVICE_NAME}"
|
||||||
|
|
||||||
|
if [[ ! -f "${SOURCE_JAR}" ]]; then
|
||||||
|
echo "Missing built jar: ${SOURCE_JAR}" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ! -f "${SOURCE_SERVICE}" ]]; then
|
||||||
|
echo "Missing service file: ${SOURCE_SERVICE}" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p "${APP_TARGET_DIR}"
|
||||||
|
|
||||||
|
if [[ "$(realpath "${SOURCE_JAR}")" != "$(realpath -m "${APP_JAR}")" ]]; then
|
||||||
|
install -m 0644 "${SOURCE_JAR}" "${APP_JAR}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
sudo install -m 0644 "${SOURCE_SERVICE}" "${SYSTEMD_SERVICE}"
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
sudo systemctl enable "${SERVICE_NAME}"
|
||||||
|
sudo systemctl restart "${SERVICE_NAME}"
|
||||||
|
sudo systemctl --no-pager --full status "${SERVICE_NAME}"
|
||||||
Reference in New Issue
Block a user