-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow multiple modules in a single file
More than one module can now be defined in the same garden.yml file. This is useful e.g. where more than one Dockerfile is used to build the same container (e.g. for development and production). Within a garden.yml file, each module definition lives within a YAML document (separated by `---`).
- Loading branch information
Showing
35 changed files
with
745 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Example project demonstrating several modules/Dockerfiles in one directory | ||
|
||
This project shows how you can configure several modules in a single directory. | ||
|
||
This is useful, for exmample, when you want to use more than one Dockerfile (e.g. one for development, one for production). | ||
|
||
```shell | ||
$ garden deploy | ||
Deploy 🚀 | ||
|
||
✔ dev → Building dev:602ae70cb8-1550064758... → Done (took 9.1 sec) | ||
✔ prod → Building prod:602ae70cb8-1550064758... → Done (took 8.9 sec) | ||
✔ prod → Deploying version 602ae70cb8-1550064758... → Done (took 4 sec) | ||
✔ dev → Deploying version 602ae70cb8-1550064758... → Done (took 3.9 sec) | ||
|
||
Done! ✔️ | ||
|
||
$ garden call dev | ||
✔ Sending HTTP GET request to http://multiple-modules.local.app.garden/hello-dev | ||
|
||
200 OK | ||
|
||
Greetings! This container was built with Dockerfile-dev. | ||
|
||
$ garden call prod | ||
✔ Sending HTTP GET request to http://multiple-modules.local.app.garden/hello-prod | ||
|
||
200 OK | ||
|
||
Greetings! This container was built with Dockerfile-prod. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
project: | ||
name: multiple-modules | ||
environments: | ||
- name: local | ||
providers: | ||
- name: local-kubernetes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
Dockerfile | ||
garden.yml | ||
app.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM node:9-alpine | ||
|
||
ENV PORT=8080 | ||
ENV ENVIRONMENT=dev | ||
ENV HELLO_PATH=/hello-dev | ||
EXPOSE ${PORT} | ||
WORKDIR /app | ||
|
||
ADD package.json /app | ||
RUN npm install | ||
|
||
ADD . /app | ||
|
||
CMD ["npm", "start"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM node:9-alpine | ||
|
||
ENV PORT=8080 | ||
ENV ENVIRONMENT=prod | ||
ENV HELLO_PATH=/hello-prod | ||
EXPOSE ${PORT} | ||
WORKDIR /app | ||
|
||
ADD package.json /app | ||
RUN npm install | ||
|
||
ADD . /app | ||
|
||
CMD ["npm", "start"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const express = require('express'); | ||
const app = express(); | ||
|
||
// These environment variables are set differently in Dockerfile-dev and Dockerfile-prod | ||
const envName = process.env.ENVIRONMENT; | ||
const helloPath = process.env.HELLO_PATH | ||
|
||
const helloMsg = `Greetings! This container was built with Dockerfile-${envName}.`; | ||
|
||
app.get(helloPath, (req, res) => res.send(helloMsg)); | ||
|
||
module.exports = { app } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module: | ||
name: dev | ||
description: Node service (dev mode) | ||
dockerfile: Dockerfile-dev | ||
type: container | ||
services: | ||
- name: dev | ||
command: [npm, start] | ||
ports: | ||
- name: http | ||
containerPort: 8080 | ||
ingresses: | ||
- path: /hello-dev | ||
port: http | ||
tests: | ||
- name: unit | ||
args: [npm, test] | ||
|
||
--- | ||
|
||
module: | ||
name: prod | ||
description: Node service (production mode) | ||
dockerfile: Dockerfile-prod | ||
type: container | ||
services: | ||
- name: prod | ||
command: [npm, start] | ||
ports: | ||
- name: http | ||
containerPort: 8080 | ||
ingresses: | ||
- path: /hello-prod | ||
port: http | ||
tests: | ||
- name: unit | ||
args: [npm, test] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const { app } = require('./app'); | ||
|
||
app.listen(process.env.PORT, '0.0.0.0', () => console.log('Node service started')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "node-service", | ||
"version": "1.0.0", | ||
"description": "Simple Node.js docker service", | ||
"main": "main.js", | ||
"scripts": { | ||
"start": "node main.js", | ||
"test": "echo OK", | ||
"integ": "node_modules/mocha/bin/mocha test/integ.js" | ||
}, | ||
"author": "garden.io <[email protected]>", | ||
"license": "ISC", | ||
"dependencies": { | ||
"express": "^4.16.2", | ||
"request": "^2.83.0", | ||
"request-promise": "^4.2.2" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^5.1.1", | ||
"supertest": "^3.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.