Merge branch 'develop'
This commit is contained in:
10 files changed
+248
-52
No files matched your search
@@ -0,0 +1,95 @@
|
||||
name: Server Build and Deploy
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
env:
|
||||
APP_NAME: ahsarah-guide-server
|
||||
|
||||
jobs:
|
||||
build-and-release:
|
||||
runs-on: ubuntu-latest
|
||||
defaults:
|
||||
run:
|
||||
working-directory: server
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Set up JDK 21 (Corretto)
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: 21
|
||||
distribution: corretto
|
||||
cache: gradle
|
||||
|
||||
- name: Build with Gradle
|
||||
run: >
|
||||
./gradlew bootJar -x test
|
||||
-PartefactVersion="${{ github.event.release.tag_name }}"
|
||||
-PbuildChannel=stable
|
||||
-Pvendor=${{ vars.VENDOR }}
|
||||
|
||||
- name: Resolve JAR file path
|
||||
id: jar
|
||||
run: |
|
||||
JAR_PATH=$(find build/libs -name '*.jar' | head -1)
|
||||
echo "file=$JAR_PATH" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Prepare release asset
|
||||
id: asset
|
||||
run: |
|
||||
TAG="${{ github.event.release.tag_name }}"
|
||||
FILE="${{ steps.jar.outputs.file }}"
|
||||
ASSET_NAME="${APP_NAME}-${TAG}.jar"
|
||||
cp "${FILE}" "../${ASSET_NAME}"
|
||||
echo "path=${ASSET_NAME}" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Upload JAR to GitHub Release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
files: ${{ steps.asset.outputs.path }}
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Log in to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ vars.DOCKER_HUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_HUB_TOKEN }}
|
||||
|
||||
- name: Generate image tags
|
||||
id: meta
|
||||
run: |
|
||||
DOCKERHUB_USER="${{ vars.DOCKER_HUB_USERNAME }}"
|
||||
echo "tag_version=${DOCKERHUB_USER}/${APP_NAME}:${{ github.event.release.tag_name }}" >> "$GITHUB_OUTPUT"
|
||||
echo "tag_latest=${DOCKERHUB_USER}/${APP_NAME}:latest" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: server
|
||||
file: server/Dockerfile.ci
|
||||
build-args: |
|
||||
JAR_FILE=${{ steps.jar.outputs.file }}
|
||||
IMAGE_VERSION=${{ github.event.release.tag_name }}
|
||||
IMAGE_VENDOR=${{ vars.VENDOR }}
|
||||
BUILD_DATE=${{ github.event.release.published_at }}
|
||||
push: true
|
||||
tags: |
|
||||
${{ steps.meta.outputs.tag_version }}
|
||||
${{ steps.meta.outputs.tag_latest }}
|
||||
|
||||
- name: Push README to Docker Hub
|
||||
uses: christian-korneck/update-container-description-action@v1
|
||||
env:
|
||||
DOCKER_USER: ${{ vars.DOCKER_HUB_USERNAME }}
|
||||
DOCKER_PASS: ${{ secrets.DOCKER_HUB_TOKEN }}
|
||||
with:
|
||||
destination_container_repo: ${{ vars.DOCKER_HUB_USERNAME }}/${{ env.APP_NAME }}
|
||||
provider: dockerhub
|
||||
readme_file: server/README.md
|
||||
@@ -0,0 +1,109 @@
|
||||
name: Web Build and Deploy
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build release archive
|
||||
runs-on: ubuntu-latest
|
||||
defaults:
|
||||
run:
|
||||
working-directory: web
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 24
|
||||
cache: pnpm
|
||||
cache-dependency-path: web/pnpm-lock.yaml
|
||||
|
||||
- name: Setup pnpm
|
||||
uses: pnpm/action-setup@v4
|
||||
with:
|
||||
version: 11
|
||||
|
||||
- name: Install dependencies
|
||||
run: pnpm install --frozen-lockfile
|
||||
|
||||
- name: Build release archive
|
||||
run: pnpm build:tar
|
||||
|
||||
- name: Clean up previous build artefacts on server
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ vars.DEPLOY_HOST }}
|
||||
username: ${{ vars.DEPLOY_USER }}
|
||||
port: ${{ vars.DEPLOY_PORT }}
|
||||
key: ${{ secrets.DEPLOY_SSH_KEY }}
|
||||
command: rm -rf /tmp/dist.tar.gz /tmp/dist.tar.gz/
|
||||
|
||||
- name: Upload artefact to server
|
||||
uses: appleboy/scp-action@v0.1.7
|
||||
with:
|
||||
host: ${{ vars.DEPLOY_HOST }}
|
||||
username: ${{ vars.DEPLOY_USER }}
|
||||
port: ${{ vars.DEPLOY_PORT }}
|
||||
key: ${{ secrets.DEPLOY_SSH_KEY }}
|
||||
source: "dist.tar.gz"
|
||||
target: "/tmp/"
|
||||
|
||||
upload-release-asset:
|
||||
name: Upload to GitHub Release
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Download artefact from server
|
||||
env:
|
||||
DEPLOY_HOST: ${{ vars.DEPLOY_HOST }}
|
||||
DEPLOY_USER: ${{ vars.DEPLOY_USER }}
|
||||
DEPLOY_PORT: ${{ vars.DEPLOY_PORT }}
|
||||
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
|
||||
run: |
|
||||
set -e
|
||||
SSH_DIR="${RUNNER_TEMP}/ssh"
|
||||
mkdir -p "$SSH_DIR"
|
||||
chmod 700 "$SSH_DIR"
|
||||
printf '%s\n' "$DEPLOY_SSH_KEY" > "$SSH_DIR/key"
|
||||
chmod 600 "$SSH_DIR/key"
|
||||
scp -i "$SSH_DIR/key" \
|
||||
-P "$DEPLOY_PORT" \
|
||||
-o StrictHostKeyChecking=accept-new \
|
||||
-o UserKnownHostsFile="$SSH_DIR/known_hosts" \
|
||||
"${DEPLOY_USER}@${DEPLOY_HOST}:/tmp/dist.tar.gz" \
|
||||
./dist.tar.gz
|
||||
rm -rf "$SSH_DIR"
|
||||
|
||||
- name: Upload release asset to GitHub
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
files: dist.tar.gz
|
||||
|
||||
deploy-to-server:
|
||||
name: Deploy to onixbyte.cn
|
||||
needs: [build, upload-release-asset]
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Extract archive and deploy
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ vars.DEPLOY_HOST }}
|
||||
username: ${{ vars.DEPLOY_USER }}
|
||||
port: ${{ vars.DEPLOY_PORT }}
|
||||
key: ${{ secrets.DEPLOY_SSH_KEY }}
|
||||
script_stop: true
|
||||
script: |
|
||||
set -e
|
||||
DEPLOY_PATH="${{ vars.DEPLOY_PATH }}"
|
||||
mkdir -p "$DEPLOY_PATH"
|
||||
rm -rf "$DEPLOY_PATH"/*
|
||||
tar -xzf /tmp/dist.tar.gz -C "$DEPLOY_PATH" --strip-components=1
|
||||
chown -R caddy:caddy "$DEPLOY_PATH"
|
||||
rm -f /tmp/dist.tar.gz
|
||||
@@ -12,7 +12,7 @@ LABEL org.opencontainers.image.title="ahsarah-guide-server" \
|
||||
org.opencontainers.image.description="REST API backend for Ahsarah Guide" \
|
||||
org.opencontainers.image.version="${IMAGE_VERSION}" \
|
||||
org.opencontainers.image.vendor="${IMAGE_VENDOR}" \
|
||||
org.opencontainers.image.source="https://onixbyte.dev/onixbyte/ahsarah-guide" \
|
||||
org.opencontainers.image.source="https://github.com/onixbyte/ahsarah-guide" \
|
||||
org.opencontainers.image.licenses="MIT" \
|
||||
org.opencontainers.image.created="${BUILD_DATE}"
|
||||
|
||||
|
||||
+16
-11
@@ -23,6 +23,22 @@ java {
|
||||
}
|
||||
}
|
||||
|
||||
// Generate META-INF/build-info.properties at build time. The build version comes
|
||||
// from the project version (driven by the git tag in CI); channel and vendor are
|
||||
// stamped alongside it so the runtime no longer needs template placeholders.
|
||||
springBoot {
|
||||
buildInfo {
|
||||
properties {
|
||||
additional.set(
|
||||
mapOf(
|
||||
"channel" to buildChannel,
|
||||
"vendor" to vendor
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// BOMs are imported as platforms, so they cannot be bundled.
|
||||
implementation(platform(libs.aws.sdk.bom))
|
||||
@@ -48,17 +64,6 @@ dependencies {
|
||||
testRuntimeOnly(libs.bundles.testRuntime)
|
||||
}
|
||||
|
||||
tasks.processResources {
|
||||
filesMatching("application.yaml") {
|
||||
println("appVersion = ${artefactVersion}, channel = ${buildChannel}, vendor = ${vendor}")
|
||||
expand(
|
||||
"appVersion" to artefactVersion,
|
||||
"channel" to buildChannel,
|
||||
"vendor" to vendor
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
@@ -1,14 +1 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
dependencyResolutionManagement {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.name = "ahsarah-guide-server"
|
||||
@@ -2,10 +2,8 @@ package com.onixbyte.ahsarahguide.config;
|
||||
|
||||
import com.onixbyte.ahsarahguide.interceptor.GitHubWebhookInterceptor;
|
||||
import com.onixbyte.ahsarahguide.interceptor.TrafficInterceptor;
|
||||
import com.onixbyte.ahsarahguide.properties.AppProperties;
|
||||
import com.onixbyte.ahsarahguide.security.resolver.CurrentUserArgumentResolver;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
@@ -14,7 +12,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(AppProperties.class)
|
||||
public class AppConfig implements WebMvcConfigurer {
|
||||
|
||||
private final TrafficInterceptor trafficInterceptor;
|
||||
|
||||
@@ -4,13 +4,16 @@ import io.swagger.v3.oas.annotations.OpenAPIDefinition;
|
||||
import io.swagger.v3.oas.annotations.info.Contact;
|
||||
import io.swagger.v3.oas.annotations.info.Info;
|
||||
import io.swagger.v3.oas.annotations.info.License;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import org.springdoc.core.customizers.OpenApiCustomizer;
|
||||
import org.springframework.boot.info.BuildProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@OpenAPIDefinition(
|
||||
info = @Info(
|
||||
title = "Ahsarah Guide Server",
|
||||
description = "API for Ahsarah Guide",
|
||||
version = "1.4.0",
|
||||
contact = @Contact(
|
||||
name = "Zihlu Wang",
|
||||
email = "zihlu.wang@onixbyte.com"
|
||||
@@ -23,4 +26,20 @@ import org.springframework.context.annotation.Configuration;
|
||||
)
|
||||
@Configuration
|
||||
public class OpenApiConfiguration {
|
||||
|
||||
/**
|
||||
* Overrides the OpenAPI info version with the packaged build version so the
|
||||
* docs always match the released artefact instead of a hard-coded value.
|
||||
*
|
||||
* @param buildProperties the build-info properties generated at build time
|
||||
* @return customiser that stamps the build version onto the API info
|
||||
*/
|
||||
@Bean
|
||||
public OpenApiCustomizer versionCustomizer(BuildProperties buildProperties) {
|
||||
return openApi -> {
|
||||
if (openApi.getInfo() != null) {
|
||||
openApi.getInfo().setVersion(buildProperties.getVersion());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
package com.onixbyte.ahsarahguide.manager;
|
||||
|
||||
import com.onixbyte.ahsarahguide.properties.AppProperties;
|
||||
import org.springframework.boot.info.BuildProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class AppManager {
|
||||
|
||||
private final AppProperties appProperties;
|
||||
private final BuildProperties buildProperties;
|
||||
|
||||
public AppManager(AppProperties appProperties) {
|
||||
this.appProperties = appProperties;
|
||||
public AppManager(BuildProperties buildProperties) {
|
||||
this.buildProperties = buildProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -19,9 +19,9 @@ public class AppManager {
|
||||
*/
|
||||
public String getVersion() {
|
||||
return "v%s-%s by @%s".formatted(
|
||||
appProperties.version(),
|
||||
appProperties.channel(),
|
||||
appProperties.vendor()
|
||||
buildProperties.getVersion(),
|
||||
buildProperties.get("channel"),
|
||||
buildProperties.get("vendor")
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package com.onixbyte.ahsarahguide.properties;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@ConfigurationProperties(prefix = "app.common")
|
||||
public record AppProperties(
|
||||
String version,
|
||||
String channel,
|
||||
String vendor
|
||||
) {
|
||||
}
|
||||
@@ -53,8 +53,3 @@ logging:
|
||||
org.hibernate:
|
||||
orm.connections.pooling: off
|
||||
|
||||
app:
|
||||
common:
|
||||
version: ${appVersion}
|
||||
channel: ${channel}
|
||||
vendor: ${vendor}
|
||||
Reference in new issue
Block a user