diff --git a/.devspace/cache.yaml b/.devspace/cache.yaml
new file mode 100644
index 0000000..bca4d23
--- /dev/null
+++ b/.devspace/cache.yaml
@@ -0,0 +1,4 @@
+varsEncrypted: true
+lastContext:
+ namespace: template-java
+ context: docker-desktop
diff --git a/Dockerfile b/Dockerfile
index 367014a..b64401e 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,6 +1,11 @@
+################ Build & Dev ################
+# Build stage will be used:
+# - for building the application for production
+# - as target for development (see devspace.yaml)
FROM maven:3.8.7-openjdk-18-slim as base
FROM base as ci
+# Create project directory (workdir)
WORKDIR /app
COPY . .
@@ -8,8 +13,16 @@ FROM ci as builder
WORKDIR /app
RUN mvn package -Dmaven.test.skip=true
-FROM builder as shipment
+################ Production ################
+# Creates a minimal image for production using distroless base image
+# More info here: https://github.com/GoogleContainerTools/distroless
+# FROM builder as shipment
+FROM gcr.io/distroless/java:11 as production
WORKDIR /app
-COPY --from=builder /app/target/template-java.jar .
+COPY --from=builder /app/target/app.jar .
-ENTRYPOINT ["java","-jar", "/app/template-java.jar"]
\ No newline at end of file
+# Application port (optional)
+EXPOSE 8080
+
+# Container start command for production
+ENTRYPOINT ["java","-jar", "/app/app.jar"]
diff --git a/devspace.yaml b/devspace.yaml
index 6569b54..38c305e 100644
--- a/devspace.yaml
+++ b/devspace.yaml
@@ -3,7 +3,7 @@ name: template-java
# `vars` specifies variables which may be used as ${VAR_NAME} in devspace.yaml
vars:
- IMAGE: ghcr.io/devxp-tech/template-java:7df51a75 #:devspace
+ IMAGE: ghcr.io/devxp-tech/template-java
pipelines:
# Override the default pipeline for 'devspace dev'
@@ -16,13 +16,13 @@ pipelines:
# This is a list of `images` that DevSpace can build for this project
# We recommend to skip image building during development (devspace dev) as much as possible
images:
- template-java:
+ app:
image: ${IMAGE}
dockerfile: ./Dockerfile
# This is a list of `deployments` that DevSpace can create for this project
deployments:
- template-java:
+ app:
helm:
chart:
name: devxp-dev
@@ -37,37 +37,33 @@ deployments:
limits:
cpu: "200m"
memory: "512Mi"
- envs:
- - name: SERVICE_NAME
- value: "template-java"
- - name: INSECURE_MODE
- value: "true"
- - name: OTEL_EXPORTER_OTLP_ENDPOINT
- value: opentelemetry-collector.tracing.svc.cluster.local:4317
# This is a list of `dev` containers that are based on the containers created by your deployments
dev:
- template-java:
+ app:
# Search for the container that runs this image
imageSelector: ${IMAGE}
# Replace the container image with this dev-optimized image (allows to skip image building during development)
- devImage: ghcr.io/loft-sh/devspace-containers/go:1.18-alpine
+ # devImage: ghcr.io/loft-sh/devspace-containers/go:1.18-alpine
logs: {}
command:
- - go
- - run
- - main.go
+ - mvn spring-boot:run
# Sync files between the local filesystem and the development container
sync:
- path: ./:/app
uploadExcludeFile: .dockerignore
excludePaths:
- - "**"
- - "!**/*.go"
- - "!go.mod"
- - "!go.sum"
+ - .git/
+ uploadExcludePaths:
+ - Dockerfile
+ - target/
onUpload:
- restartContainer: true
+ execRemote:
+ onBatch:
+ command: sh
+ args:
+ - -c
+ - mvn compile >>/dev/pts/0 || exit 0
# Forward the following ports to be able access your application via localhost
ports:
- port: 23450:2345
diff --git a/devspace_start.sh b/devspace_start.sh
new file mode 100644
index 0000000..a17f195
--- /dev/null
+++ b/devspace_start.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+echo "Installing maven dependencies"
+
+COLOR_CYAN="\033[0;36m"
+COLOR_RESET="\033[0m"
+
+echo -e "${COLOR_CYAN}
+ ____ ____
+ | _ \ _____ __/ ___| _ __ __ _ ___ ___
+ | | | |/ _ \ \ / /\___ \| '_ \ / _\` |/ __/ _ \\
+ | |_| | __/\ V / ___) | |_) | (_| | (_| __/
+ |____/ \___| \_/ |____/| .__/ \__,_|\___\___|
+ |_|
+${COLOR_RESET}
+Welcome to your development container!
+
+This is how you can work with it:
+- Run \`${COLOR_CYAN}mvn spring-boot:run${COLOR_RESET}\` to run the application
+- Run \`${COLOR_CYAN}mvn package -T 1C -U -Dmaven.test.skip=true${COLOR_RESET}\` to build the application
+- ${COLOR_CYAN}Files will be synchronized${COLOR_RESET} between your local machine and this container (triggers build process)
+- Some ports will be forwarded, so you can access this container on your local machine via ${COLOR_CYAN}localhost${COLOR_RESET}:"
+
+devspace list ports
+
+bash
diff --git a/pom.xml b/pom.xml
index a1723dd..144988f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,7 +9,7 @@
com.devxp-tech
- template-java
+ app
0.0.1-SNAPSHOT
template-java
Demo project for Spring Boot