Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0cfafc1

Browse files
committedSep 20, 2021
chore: update quickstart example
1 parent 35dd010 commit 0cfafc1

File tree

6 files changed

+1780
-35
lines changed

6 files changed

+1780
-35
lines changed
 

‎examples/quickstart/.gitignore

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
2-
3-
# Exclude .devspace generated files
4-
.devspace/
1+
Dockerfile
2+
.devspace/
3+
chart/
4+
node_modules/
5+
test/
6+
devspace.yaml

‎examples/quickstart/Dockerfile

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
FROM node:13.14-alpine
22

3-
RUN mkdir /app
3+
# Set working directory
44
WORKDIR /app
55

6-
COPY package.json .
6+
# Add package.json to WORKDIR and install dependencies
7+
COPY package*.json ./
78
RUN npm install
89

10+
# Add source code files to WORKDIR
911
COPY . .
1012

13+
# Application port (optional)
14+
EXPOSE 3000
15+
16+
# Debugging port (optional)
17+
# For remote debugging, add this port to devspace.yaml: dev.ports[*].forward[*].port: 9229
18+
EXPOSE 9229
19+
20+
# Container start command (DO NOT CHANGE and see note below)
1121
CMD ["npm", "start"]
22+
23+
# To start using a different `npm run [name]` command (e.g. to use nodemon + debugger),
24+
# edit devspace.yaml:
25+
# 1) remove: images.app.injectRestartHelper (or set to false)
26+
# 2) add this: images.app.cmd: ["npm", "run", "dev"]

‎examples/quickstart/devspace.yaml

Lines changed: 75 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,81 @@
11
version: v1beta11
2+
3+
# `vars` specifies variables which may be used as ${VAR_NAME} in devspace.yaml
24
vars:
3-
- name: IMAGE
4-
value: myusername/devspace
5-
images:
6-
default:
7-
image: ${IMAGE}
5+
- name: IMAGE
6+
value: myusername/app
7+
8+
# `deployments` tells DevSpace how to deploy this project
89
deployments:
9-
- name: quickstart
10-
helm:
11-
componentChart: true
12-
values:
13-
containers:
14-
- image: ${IMAGE}
15-
service:
16-
ports:
17-
- port: 3000
10+
- name: quickstart
11+
# This deployment uses `helm` but you can also define `kubectl` deployments or kustomizations
12+
helm:
13+
# We are deploying the so-called Component Chart: https://devspace.sh/component-chart/docs
14+
componentChart: true
15+
# Under `values` we can define the values for this Helm chart used during `helm install/upgrade`
16+
# You may also use `valuesFiles` to load values from files, e.g. valuesFiles: ["values.yaml"]
17+
values:
18+
containers:
19+
- image: ${IMAGE} # Use the value of our `${IMAGE}` variable here (see vars above)
20+
service:
21+
ports:
22+
- port: 3000
23+
24+
# `dev` only applies when you run `devspace dev`
1825
dev:
26+
# `dev.ports` specifies all ports that should be forwarded while `devspace dev` is running
27+
# Port-forwarding lets you access your application via localhost on your local machine
1928
ports:
20-
- imageSelector: ${IMAGE}
21-
forward:
22-
- port: 3000
29+
- imageSelector: ${IMAGE} # Select the Pod that runs our `${IMAGE}`
30+
forward:
31+
- port: 3000
32+
33+
# `dev.open` tells DevSpace to open certain URLs as soon as they return HTTP status 200
34+
# Since we configured port-forwarding, we can use a localhost address here to access our application
35+
open:
36+
- url: http://localhost:3000
37+
38+
# `dev.sync` configures a file sync between our Pods in k8s and your local project files
2339
sync:
24-
- imageSelector: ${IMAGE}
25-
uploadExcludePaths:
26-
- node_modules
40+
- imageSelector: ${IMAGE} # Select the Pod that runs our `${IMAGE}`
41+
excludePaths:
42+
- .git/
43+
uploadExcludeFile: .gitignore
44+
45+
# `dev.terminal` tells DevSpace to open a terminal as a last step during `devspace dev`
46+
terminal:
47+
imageSelector: ${IMAGE} # Select the Pod that runs our `${IMAGE}`
48+
# With this optional `command` we can tell DevSpace to run a script when opening the terminal
49+
# This is often useful to display help info for new users or perform initial tasks (e.g. installing dependencies)
50+
# DevSpace has generated an example ./devspace_start.sh file in your local project - Feel free to customize it!
51+
command: ["./devspace_start.sh"]
52+
53+
# Since our Helm charts and manifests deployments are often optimized for production,
54+
# DevSpace let's you swap out Pods dynamically to get a better dev environment
55+
replacePods:
56+
- imageSelector: ${IMAGE} # Select the Pod that runs our `${IMAGE}`
57+
# Since the `${IMAGE}` used to start our main application pod may be distroless or not have any dev tooling, let's replace it with a dev-optimized image
58+
# DevSpace provides a sample image here but you can use any image for your specific needs
59+
replaceImage: loftsh/javascript:latest
60+
# Besides replacing the container image, let's also apply some patches to the `spec` of our Pod
61+
# We are overwriting `command` + `args` for the first container in our selected Pod, so it starts with `sleep 9999999`
62+
# Using `sleep 9999999` as PID 1 (instead of the regular ENTRYPOINT), allows you to start the application manually
63+
patches:
64+
- op: replace
65+
path: spec.containers[0].command
66+
value: ["sleep"]
67+
- op: replace
68+
path: spec.containers[0].args
69+
value: ["9999999"]
70+
71+
# `profiles` lets you modify the config above for different environments (e.g. dev vs production)
72+
profiles:
73+
# This profile is called `production` and you can use it for example using: devspace deploy -p production
74+
# We generally recommend to use the base config without any profiles as optimized for development (e.g. image build+push is disabled)
75+
- name: production
76+
# This profile adds our image to the config so that DevSpace will build, tag and push our image before the deployment
77+
merge:
78+
images:
79+
app:
80+
image: ${IMAGE} # Use the value of our `${IMAGE}` variable here (see vars above)
81+
dockerfile: ./Dockerfile

‎examples/quickstart/devspace_start.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
set +e # Continue on errors
3+
4+
export NODE_ENV=development
5+
if [ -f "yarn.lock" ]; then
6+
echo "Installing Yarn Dependencies"
7+
yarn
8+
else
9+
if [ -f "package.json" ]; then
10+
echo "Installing NPM Dependencies"
11+
npm install
12+
fi
13+
fi
14+
15+
COLOR_CYAN="\033[0;36m"
16+
COLOR_RESET="\033[0m"
17+
18+
echo -e "${COLOR_CYAN}
19+
____ ____
20+
| _ \ _____ __/ ___| _ __ __ _ ___ ___
21+
| | | |/ _ \ \ / /\___ \| '_ \ / _\` |/ __/ _ \\
22+
| |_| | __/\ V / ___) | |_) | (_| | (_| __/
23+
|____/ \___| \_/ |____/| .__/ \__,_|\___\___|
24+
|_|
25+
${COLOR_RESET}
26+
Welcome to your development container!
27+
This is how you can work with it:
28+
- Run \`${COLOR_CYAN}npm start${COLOR_RESET}\` to start the application
29+
- ${COLOR_CYAN}Files will be synchronized${COLOR_RESET} between your local machine and this container
30+
- Some ports will be forwarded, so you can access this container on your local machine via ${COLOR_CYAN}http://localhost:3000${COLOR_RESET}
31+
"
32+
33+
bash

‎examples/quickstart/index.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
1-
var express = require('express');
2-
var app = express();
1+
const express = require('express')
2+
const app = express()
3+
const port = 3000
34

4-
app.get('/', function (req, res) {
5-
res.send('Hello World!');
6-
});
5+
app.get('/', (req, res) => {
6+
res.send(`
7+
<html>
8+
<head>
9+
<link rel="stylesheet" href="https://devspace.sh/css/quickstart.css">
10+
</head>
11+
<body>
12+
<img src="https://devspace.sh/images/congrats.gif" />
13+
<h1>You deployed this project with DevSpace!</h1>
14+
<div>
15+
<h2>Now it's time to code:</h2>
16+
<ol>
17+
<li>Edit this text in <code>index.js</code> and save the file</li>
18+
<li>Check the logs to see how DevSpace restarts your container</li>
19+
<li>Reload browser to see the changes</li>
20+
</ol>
21+
</div>
22+
</body>
23+
</html>
24+
`)
25+
})
726

8-
app.listen(3000, function () {
9-
console.log('Example app listening on port 3000!');
10-
});
27+
app.listen(port, () => console.log("Example app listening on http://localhost:" + port))

‎examples/quickstart/package-lock.json

Lines changed: 1624 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.