Compare commits
12 Commits
211350f8a4
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
8579066a1e
|
|||
|
42157c4abc
|
|||
|
7e53d48d41
|
|||
|
7c4c9001d0
|
|||
|
f170687cb8
|
|||
| 4f3b03cec5 | |||
|
|
edfacb05a1 | ||
|
|
65fb1a3311 | ||
|
|
55eb9b5c12 | ||
|
ed71fce96f
|
|||
|
f1554f1131
|
|||
|
|
ea47e63660 |
51
.gitea/workflows/docker.yml
Normal file
51
.gitea/workflows/docker.yml
Normal file
@@ -0,0 +1,51 @@
|
||||
name: Build and Push Multi-Arch Docker Image
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
|
||||
- name: Set Registry Domain
|
||||
run: |
|
||||
REGISTRY_DOMAIN=$(echo "${{ github.server_url }}" | sed 's|https://||' | sed 's|http://||')
|
||||
echo "REGISTRY_DOMAIN=$REGISTRY_DOMAIN" >> $GITHUB_ENV
|
||||
|
||||
- name: Login to Gitea Registry
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
registry: ${{ env.REGISTRY_DOMAIN }}
|
||||
username: ${{ secrets.REGISTRY_USER }}
|
||||
password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||
|
||||
- name: Set up JDK
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: '17'
|
||||
distribution: 'temurin'
|
||||
|
||||
- name: Extract Version
|
||||
run: |
|
||||
VERSION=$(grep -m1 '<version>' pom.xml | sed -E 's/.*<version>([^<]+)<\/version>.*/\1/')
|
||||
echo "VERSION=$VERSION" >> $GITHUB_ENV
|
||||
echo "MAJOR=$(echo $VERSION | cut -d. -f1)" >> $GITHUB_ENV
|
||||
echo "MAJOR_MINOR=$(echo $VERSION | cut -d. -f1,2)" >> $GITHUB_ENV
|
||||
|
||||
- name: Build and Push Multi-Arch Image
|
||||
run: |
|
||||
docker buildx build \
|
||||
--platform linux/amd64,linux/arm64 \
|
||||
-t ${{ env.REGISTRY_DOMAIN }}/${{ github.repository }}:latest \
|
||||
-t ${{ env.REGISTRY_DOMAIN }}/${{ github.repository }}:${{ env.MAJOR }} \
|
||||
-t ${{ env.REGISTRY_DOMAIN }}/${{ github.repository }}:${{ env.MAJOR_MINOR }} \
|
||||
-t ${{ env.REGISTRY_DOMAIN }}/${{ github.repository }}:${{ env.VERSION }} \
|
||||
--push .
|
||||
11
.github/dependabot.yml
vendored
11
.github/dependabot.yml
vendored
@@ -1,11 +0,0 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
|
||||
- package-ecosystem: "maven"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
39
.github/workflows/deploy-hetzner.yaml
vendored
39
.github/workflows/deploy-hetzner.yaml
vendored
@@ -1,39 +0,0 @@
|
||||
---
|
||||
name: 'deploy to hetzner'
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Cloning repo
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up JDK 21
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: '21'
|
||||
distribution: 'temurin'
|
||||
cache: maven
|
||||
|
||||
- name: Build and test with Maven
|
||||
run: mvn --batch-mode --update-snapshots verify
|
||||
|
||||
- name: Push to dokku
|
||||
timeout-minutes: 20
|
||||
uses: dokku/github-action@v1
|
||||
with:
|
||||
branch: main
|
||||
git_remote_url: ${{ secrets.HETZNER_GIT_URI }}
|
||||
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
git_push_flags: --force
|
||||
@@ -11,9 +11,11 @@ USER app
|
||||
|
||||
# Copy all needed project files to a folder
|
||||
COPY --chown=app ./.mvn/ .mvn
|
||||
COPY --chown=app ./mvnw ./pom.xml ./app.json ./
|
||||
COPY --chown=app ./mvnw ./pom.xml ./
|
||||
COPY --chown=app ./src ./src
|
||||
|
||||
RUN curl -OL https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar
|
||||
|
||||
# Build the production package
|
||||
RUN ./mvnw --batch-mode clean verify -Pproduction -DskipTests
|
||||
|
||||
@@ -24,7 +26,8 @@ RUN useradd -m app
|
||||
USER app
|
||||
|
||||
COPY --chown=app --from=build /usr/src/app/target/*.jar /usr/app/website.jar
|
||||
COPY --chown=app --from=build /usr/src/app/opentelemetry-javaagent.jar /usr/app/opentelemetry-javaagent.jar
|
||||
|
||||
HEALTHCHECK CMD curl --fail http://localhost:5000/actuator/health/liveness || exit 1
|
||||
HEALTHCHECK CMD curl --fail http://localhost:8080/actuator/health || exit 1
|
||||
|
||||
CMD ["java", "-jar", "/usr/app/website.jar"]
|
||||
|
||||
20
Makefile
Normal file
20
Makefile
Normal file
@@ -0,0 +1,20 @@
|
||||
REMOTE_HOST = mars3142@172.16.20.1
|
||||
PROJECT_NAME = firmware-hq
|
||||
SERVICE_NAME = website
|
||||
RASPI_PATH = /mnt/data/${PROJECT_NAME}
|
||||
|
||||
install: build deploy import cleanup
|
||||
|
||||
build:
|
||||
docker buildx build --platform linux/arm64 --no-cache -t ${PROJECT_NAME}/${SERVICE_NAME}:latest -o type=docker,dest=./${SERVICE_NAME}-arm64.tar .
|
||||
|
||||
deploy:
|
||||
scp ./${SERVICE_NAME}-arm64.tar ${REMOTE_HOST}:${RASPI_PATH}/
|
||||
|
||||
import:
|
||||
ssh ${REMOTE_HOST} "sudo docker load -i ${RASPI_PATH}/${SERVICE_NAME}-arm64.tar && rm ${RASPI_PATH}/${SERVICE_NAME}-arm64.tar"
|
||||
|
||||
cleanup:
|
||||
rm -f ${SERVICE_NAME}-arm64.tar
|
||||
|
||||
.PHONY: build deploy import cleanup
|
||||
14
app.json
14
app.json
@@ -1,14 +0,0 @@
|
||||
{
|
||||
"healthchecks": {
|
||||
"web": [
|
||||
{
|
||||
"type": "readiness",
|
||||
"name": "web check",
|
||||
"description": "Checking if the app responds to the /actuator/health/readiness endpoint",
|
||||
"path": "/actuator/health/readiness",
|
||||
"port": 5000,
|
||||
"attempts": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
8
pom.xml
8
pom.xml
@@ -7,21 +7,21 @@
|
||||
<groupId>dev.mars3142.fhq</groupId>
|
||||
<artifactId>website</artifactId>
|
||||
<name>website</name>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<java.version>21</java.version>
|
||||
<vaadin.version>24.5.0.beta3</vaadin.version>
|
||||
<vaadin.version>24.6.0.alpha1</vaadin.version>
|
||||
<spring-cloud.version>2023.0.3</spring-cloud.version>
|
||||
<spring-cloud-gcp.version>5.4.1</spring-cloud-gcp.version>
|
||||
<spring-modulith.version>1.2.4</spring-modulith.version>
|
||||
<spring-modulith.version>1.2.5</spring-modulith.version>
|
||||
</properties>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.3.4</version>
|
||||
<version>3.3.5</version>
|
||||
</parent>
|
||||
|
||||
<repositories>
|
||||
|
||||
9
src/main/java/dev/mars3142/fhq/client/AuthClient.java
Normal file
9
src/main/java/dev/mars3142/fhq/client/AuthClient.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package dev.mars3142.fhq.client;
|
||||
|
||||
import org.springframework.web.service.annotation.GetExchange;
|
||||
|
||||
public interface AuthClient {
|
||||
|
||||
@GetExchange("/v1/auth")
|
||||
String getAuth();
|
||||
}
|
||||
@@ -1,9 +1,16 @@
|
||||
package dev.mars3142.fhq.client;
|
||||
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.service.annotation.GetExchange;
|
||||
|
||||
public interface TimeZoneClient {
|
||||
|
||||
@GetExchange("/v1/timezone")
|
||||
String getTimeZone();
|
||||
|
||||
@GetExchange("/v1/timezone/{area}")
|
||||
String getTimeZone(@PathVariable String area);
|
||||
|
||||
@GetExchange("/v1/timezone/{area}/{location}")
|
||||
String getTimeZone(@PathVariable String area, @PathVariable String location);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package dev.mars3142.fhq.config;
|
||||
|
||||
import dev.mars3142.fhq.client.AuthClient;
|
||||
import dev.mars3142.fhq.client.TimeZoneClient;
|
||||
import dev.mars3142.fhq.config.interceptor.AuthInterceptor;
|
||||
import lombok.val;
|
||||
import org.springframework.boot.web.client.ClientHttpRequestFactories;
|
||||
import org.springframework.boot.web.client.ClientHttpRequestFactorySettings;
|
||||
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
|
||||
@@ -17,22 +20,34 @@ public class RestClientConfig {
|
||||
@LoadBalanced
|
||||
@Bean
|
||||
RestClient.Builder restClientBuilder() {
|
||||
return RestClient.builder();
|
||||
return RestClient.builder()
|
||||
.requestInterceptor(new AuthInterceptor());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TimeZoneClient timeZoneClient(RestClient.Builder restClientBuilder) {
|
||||
RestClient restClient = restClientBuilder
|
||||
public AuthClient authClient(RestClient.Builder builder) {
|
||||
val restClient = builder
|
||||
.baseUrl("http://auth-service")
|
||||
.requestFactory(getClientRequestFactory())
|
||||
.build();
|
||||
val restClientAdapter = RestClientAdapter.create(restClient);
|
||||
val httpServiceProxyFactory = HttpServiceProxyFactory.builderFor(restClientAdapter).build();
|
||||
return httpServiceProxyFactory.createClient(AuthClient.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TimeZoneClient timeZoneClient(RestClient.Builder builder) {
|
||||
val restClient = builder
|
||||
.baseUrl("http://timezone-service")
|
||||
.requestFactory(getClientRequestFactory())
|
||||
.build();
|
||||
var restClientAdapter = RestClientAdapter.create(restClient);
|
||||
var httpServiceProxyFactory = HttpServiceProxyFactory.builderFor(restClientAdapter).build();
|
||||
val restClientAdapter = RestClientAdapter.create(restClient);
|
||||
val httpServiceProxyFactory = HttpServiceProxyFactory.builderFor(restClientAdapter).build();
|
||||
return httpServiceProxyFactory.createClient(TimeZoneClient.class);
|
||||
}
|
||||
|
||||
private ClientHttpRequestFactory getClientRequestFactory() {
|
||||
ClientHttpRequestFactorySettings clientHttpRequestFactorySettings = ClientHttpRequestFactorySettings.DEFAULTS;
|
||||
val clientHttpRequestFactorySettings = ClientHttpRequestFactorySettings.DEFAULTS;
|
||||
return ClientHttpRequestFactories.get(clientHttpRequestFactorySettings);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package dev.mars3142.fhq.config.interceptor;
|
||||
|
||||
import java.io.IOException;
|
||||
import lombok.val;
|
||||
import org.springframework.http.HttpRequest;
|
||||
import org.springframework.http.client.ClientHttpRequestExecution;
|
||||
import org.springframework.http.client.ClientHttpRequestInterceptor;
|
||||
import org.springframework.http.client.ClientHttpResponse;
|
||||
|
||||
public class AuthInterceptor implements ClientHttpRequestInterceptor {
|
||||
|
||||
@Override
|
||||
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
|
||||
throws IOException {
|
||||
val headers = request.getHeaders();
|
||||
headers.add("X-FHQ-USER-ID", "Vaadin");
|
||||
return execution.execute(request, body);
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import lombok.val;
|
||||
public class LandingPageView extends Composite<VerticalLayout> {
|
||||
|
||||
public LandingPageView(TimeZoneClient client) {
|
||||
val timeZone = client.getTimeZone();
|
||||
val timeZone = client.getTimeZone("Europe", "Berlin");
|
||||
val verticalLayout = new VerticalLayout();
|
||||
verticalLayout.setSizeFull();
|
||||
verticalLayout.add(new Text(timeZone));
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
server:
|
||||
port: ${PORT:8090}
|
||||
|
||||
vaadin:
|
||||
# To improve the performance during development.
|
||||
# For more information https://vaadin.com/docs/latest/integrations/spring/configuration#special-configuration-parameters
|
||||
allowed-packages : com.vaadin,org.vaadin,dev.hilla,dev.mars3142
|
||||
|
||||
backend:
|
||||
uri: http://localhost:8091/v1
|
||||
|
||||
eureka:
|
||||
client:
|
||||
service-url:
|
||||
defaultZone: http://localhost:8761/eureka
|
||||
@@ -1,52 +0,0 @@
|
||||
logging:
|
||||
level:
|
||||
org:atmosphere: warn
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: website
|
||||
mustache:
|
||||
check-template-location: false
|
||||
jpa:
|
||||
defer-datasource-initialization: true
|
||||
|
||||
backend:
|
||||
uri: https://api.firmware-hq.dev/v1
|
||||
|
||||
eureka:
|
||||
client:
|
||||
register-with-eureka: true
|
||||
fetch-registry: true
|
||||
service-url:
|
||||
defaultZone: http://eureka-service.web:8761/eureka
|
||||
instance:
|
||||
instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}
|
||||
|
||||
info:
|
||||
application:
|
||||
name: ${spring.application.name}
|
||||
version: '@project.version@'
|
||||
spring-cloud-version: '@spring-cloud.version@'
|
||||
spring-boot-version: '@project.parent.version@'
|
||||
|
||||
management:
|
||||
endpoint:
|
||||
health:
|
||||
probes:
|
||||
enabled: true
|
||||
|
||||
server:
|
||||
port: ${PORT:8080}
|
||||
shutdown: graceful
|
||||
error:
|
||||
include-message: on_param
|
||||
include-stacktrace: on_param
|
||||
|
||||
sentry:
|
||||
dsn: https://354321d371291036cffcdb5b1a72fd6e@o394865.ingest.us.sentry.io/4507718826262528
|
||||
environment: edge-service
|
||||
|
||||
# Set traces_sample_rate to 1.0 to capture 100%
|
||||
# of transactions for tracing.
|
||||
# We recommend adjusting this value in production.
|
||||
tracesSampleRate: 1.0
|
||||
6
src/test/resources/bootstrap.yml
Normal file
6
src/test/resources/bootstrap.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
eureka:
|
||||
client:
|
||||
register-with-eureka: false
|
||||
fetch-registry: false
|
||||
service-url:
|
||||
defaultZone: ${EUREKA}
|
||||
Reference in New Issue
Block a user