Skip to content

Commit 50a2e43

Browse files
committed
add devspace files
1 parent 9a8e7a8 commit 50a2e43

5 files changed

Lines changed: 171 additions & 0 deletions

File tree

.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Dockerfile
2+
target/
3+
4+
# Ignore .git folder
5+
.git

Dockerfile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
################ Build & Dev ################
2+
# Build stage will be used:
3+
# - for building the application for production
4+
# - as target for development (see devspace.yaml)
5+
FROM maven:3.6.3-jdk-11 as build
6+
7+
# Create project directory (workdir)
8+
WORKDIR /app
9+
10+
# Install maven dependency packages
11+
COPY pom.xml .
12+
RUN mvn -T 1C install && rm -rf target
13+
14+
# Add source code files to WORKDIR
15+
ADD . .
16+
17+
# Build application
18+
RUN ./build.sh
19+
20+
# Container start command for development
21+
# Allows DevSpace to restart the dev container
22+
# It is also possible to override this in devspace.yaml via images.*.cmd
23+
ENTRYPOINT ["./build.sh", "run"]
24+
25+
26+
################ Production ################
27+
# Creates a minimal image for production using distroless base image
28+
# More info here: https://github.com/GoogleContainerTools/distroless
29+
FROM gcr.io/distroless/java:11 as production
30+
31+
# Copy application binary from build/dev stage to the distroless container
32+
COPY --from=build /app/target/main.jar /
33+
34+
# Application port (optional)
35+
EXPOSE 8080
36+
37+
# Container start command for production
38+
ENTRYPOINT ["/main.jar"]

build.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/sh
2+
3+
# Set maven build options
4+
MAVEN_OPTS="-XX:+TieredCompilation -XX:TieredStopAtLevel=1"
5+
6+
# Remove old .jar files
7+
rm -f target/*.jar
8+
9+
# Build jar file
10+
mvn package -T 1C -U -Dmaven.test.skip=true
11+
12+
# Rename jar file
13+
cp target/*.jar target/main.jar
14+
15+
# Start application if `run` argument is passed
16+
# XXX We change "java -jar" to "mvn spring-boot:run" to start the application.
17+
# XXX We also add the extra argument to force color.
18+
# XXX Spring boot doesn't color output automatically when running inside Kubernetes.
19+
if [ "$1" = "run" ]; then
20+
#java -jar target/main.jar
21+
mvn spring-boot:run -Dspring-boot.run.arguments="--spring.output.ansi.enabled=ALWAYS"
22+
fi

devspace.yaml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
version: v1beta10
2+
3+
# `images` specifies all images that may need to be built for this project
4+
images:
5+
app: # This image is called `app` and this name `app` is referenced multiple times in the config below
6+
image: joaomlneto/example-devspace-spring-boot
7+
dockerfile: ./Dockerfile
8+
injectRestartHelper: true
9+
appendDockerfileInstructions:
10+
- USER root
11+
rebuildStrategy: ignoreContextChanges
12+
build:
13+
docker:
14+
options:
15+
target: build
16+
17+
# `deployments` tells DevSpace how to deploy this project
18+
deployments:
19+
- name: example-devspace-spring-boot
20+
# This deployment uses `helm` but you can also define `kubectl` deployments or kustomizations
21+
helm:
22+
# We are deploying the so-called Component Chart: https://devspace.sh/component-chart/docs
23+
componentChart: true
24+
# Under `values` we can define the values for this Helm chart used during `helm install/upgrade`
25+
# You may also use `valuesFiles` to load values from files, e.g. valuesFiles: ["values.yaml"]
26+
values:
27+
containers:
28+
- image: image(app):tag(app) # Use the `app` image (see `images`) and the tag DevSpace generates during image building in your Helm values
29+
service:
30+
ports:
31+
- port: 8080
32+
33+
# `dev` only applies when you run `devspace dev`
34+
dev:
35+
# `dev.ports` specifies all ports that should be forwarded while `devspace dev` is running
36+
# Port-forwarding lets you access your application via localhost on your local machine
37+
ports:
38+
- imageName: app # Select the Pod that runs our `app` image
39+
forward:
40+
- port: 8080
41+
42+
# `dev.open` tells DevSpace to open certain URLs as soon as they return HTTP status 200
43+
# Since we configured port-forwarding, we can use a localhost address here to access our application
44+
open:
45+
- url: http://localhost:8080
46+
47+
# `dev.sync` configures a file sync between our Pods in k8s and your local project files
48+
sync:
49+
- imageName: app # Select the Pod that runs our `app` image
50+
#disableDownload: true
51+
excludePaths:
52+
- .git/
53+
uploadExcludePaths:
54+
- Dockerfile
55+
- target/
56+
waitInitialSync: false
57+
# XXX ATTENTION! This is a change from the defaults XXX
58+
# Since Spring Boot devtools automatically reloads classes that were changed, instead of restarting
59+
# the container, we simply have to recompile the classes!
60+
onUpload:
61+
execRemote:
62+
command: mvn
63+
args:
64+
- compile
65+
66+
# `dev.terminal` tells DevSpace to open a terminal as a last step during `devspace dev`
67+
terminal:
68+
imageName: app
69+
# With this optional `command` we can tell DevSpace to run a script when opening the terminal
70+
# This is often useful to display help info for new users or perform initial tasks (e.g. installing dependencies)
71+
# DevSpace has generated an example ./devspace_start.sh file in your local project - Feel free to customize it!
72+
command:
73+
- ./devspace_start.sh
74+
75+
# `profiles` lets you modify the config above for different environments (e.g. dev vs production)
76+
profiles:
77+
# This profile is called `production` and you can use it for example using: devspace deploy -p production
78+
# We generally recommend to use the base config without any profiles as optimized for development (e.g. image build+push is disabled)
79+
- name: production
80+
# This profile applies patches to the config above.
81+
# In this case, it enables image building for example by removing the `disabled: true` statement for the image `app`
82+
patches:
83+
- op: remove
84+
path: images.app.build.docker.options.target

devspace_start.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
COLOR_CYAN="\033[0;36m"
4+
COLOR_RESET="\033[0m"
5+
6+
echo -e "${COLOR_CYAN}
7+
____ ____
8+
| _ \ _____ __/ ___| _ __ __ _ ___ ___
9+
| | | |/ _ \ \ / /\___ \| '_ \ / _\` |/ __/ _ \\
10+
| |_| | __/\ V / ___) | |_) | (_| | (_| __/
11+
|____/ \___| \_/ |____/| .__/ \__,_|\___\___|
12+
|_|
13+
${COLOR_RESET}
14+
15+
Welcome to your development container!
16+
This is how you can work with it:
17+
- ${COLOR_CYAN}Files will be synchronized${COLOR_RESET} between your local machine and this container
18+
- Certain files may be excluded from sync (see devspace.yaml)
19+
20+
"
21+
22+
bash

0 commit comments

Comments
 (0)