Skip to content

Commit

Permalink
scaffold out some mounting stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
pirog committed Sep 16, 2024
1 parent 0302a79 commit 09a31de
Show file tree
Hide file tree
Showing 15 changed files with 1,637 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr-core-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- list
- logs
- long-name
# - mounts
- mounts
- networking
- no-services
- orchestrator
Expand Down
26 changes: 24 additions & 2 deletions builders/lando-v4.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ module.exports = {
'healthcheck': false,
'hostnames': [],
'labels': {},
'mounts': [],
'overrides': {},
'packages': {
'git': true,
'ssh-agent': true,
'sudo': true,
},
'persistent-storage': [],
'overrides': {},
'ports': [],
'security': {
'ca': [],
Expand Down Expand Up @@ -176,6 +177,15 @@ module.exports = {
}
}

#setupMounts() {
// loop through mounts and add them
for (const mount of this.mounts) {
// as a volume
if (mount.type === 'bind') this.volumes.push(mount);
// or as build context
else if (mount.type === 'copy') this.addContext(`${mount.source}:${mount.target}`, mount.group);
}
}

#setupStorage() {
// add top level volumes
Expand Down Expand Up @@ -214,7 +224,6 @@ module.exports = {

constructor(id, options, app, lando) {
// @TODO: overrides for this.run()?
// @TODO: better appmount logix?
// @TODO: allow additonal users to be installed in config.users?
// @TODO: change lando literal to "lando product"
// @TODO: debug/lando_debug should be set with env?
Expand All @@ -228,6 +237,7 @@ module.exports = {
const user = merge({}, {gid, uid, name: username}, require('../utils/parse-v4-user')(config.user));

// add some upstream stuff and legacy stuff
// @NOTE: does this actually do something?
upstream.appMount = config['app-mount'].destination;
// this will change but for right now i just need the image stuff to passthrough
upstream.config = {image: config.image, ports: config.ports};
Expand Down Expand Up @@ -261,10 +271,12 @@ module.exports = {
this.command = config.command;
this.healthcheck = config.healthcheck;
this.hostnames = uniq([...config.hostnames, `${this.id}.${this.project}.internal`]);
this.mounts = require('../utils/normalize-mounts')(config.mounts, this);
this.packages = config.packages;
this.security = config.security;
this.security.cas.push(caCert, path.join(path.dirname(caCert), `${caDomain}.pem`));
this.storage = [
// @TODO: add any storage from mounts excludes
...require('../utils/normalize-storage')(config.storage, this),
...require('../utils/normalize-storage')(config['persistent-storage'], this),
];
Expand All @@ -273,10 +285,15 @@ module.exports = {
// top level stuff
this.tlnetworks = {[this.network]: {external: true}};

// @TODO: add in app-mount?
// @TODO: add in tmp-storage and home-storage?

// boot stuff
this.#setupBoot();
// hook system
this.#setupHooks();
// mounting system
this.#setupMounts();
// storage system
this.#setupStorage();

Expand Down Expand Up @@ -348,6 +365,7 @@ module.exports = {
networks: {[this.network]: {aliases: this.hostnames}},
user: this.user.name,
volumes: this.volumes,
working_dir: this.appMount,
});

// add any overrides on top
Expand Down Expand Up @@ -536,6 +554,10 @@ module.exports = {
}
}));
}

// finally remove the build context
fs.rmdirSync(this.context, {force: true, maxRetries: 10, recursive: true});
this.debug('removed %o-%o build-context %o', this.project, this.id, this.context);
}

getBengine() {
Expand Down
1 change: 0 additions & 1 deletion examples/lando-v4/.lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ services:
set -e
echo "stuff"
# persistent-storage
# mounts
# app-mount
Expand Down
58 changes: 58 additions & 0 deletions examples/mounts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

# 0x
profile-*

# mac files
.DS_Store

# vim swap files
*.swp

# webstorm
.idea

# vscode
.vscode
*code-workspace

# clinic
profile*
*clinic*
*flamegraph*
47 changes: 42 additions & 5 deletions examples/mounts/.lando.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,52 @@
name: lando-mounts
services:
web3:
web1:
api: 4
image:
imagefile: nginxinc/nginx-unprivileged:1.26.1
context:
- ./default-ssl.conf:/etc/nginx/conf.d/default.conf
image: nginxinc/nginx-unprivileged:1.26.1
user: nginx
ports:
- 8080/http
- 8443/https
mounts:
# bind mount a single file
- ./default-ssl.conf:/etc/nginx/conf.d/default.conf

# bind mount a single file using object notation
- source: ./default-ssl.conf
target: /etc/lando/config/default-ssl-2.conf

# bind mount the contents to the target file
- target: /etc/lando/config/obiwan
contents: |
hello
there!
# copy contents to target during config stage of image build
- target: /etc/lando/config/anakin
type: copy
group: config
content: |
this is where the fun begins
# copy content to target during user stage of image build
- target: /etc/lando/config/ahsoka
type: copy
content: |
skyguy
web2:
api: 4
image: node:18
command: npm run dev
ports:
- 3000/http
user: node
build:
app: |
npm install
mounts:
- ./:/somewhere/else

plugins:
"@lando/core": "../.."
Expand Down
42 changes: 0 additions & 42 deletions examples/mounts/README.md

This file was deleted.

21 changes: 21 additions & 0 deletions examples/mounts/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

const path = require('node:path');
const AutoLoad = require('@fastify/autoload');

// Pass --options via CLI arguments in command to enable these options.
const options = {};

module.exports = async function(fastify, opts) {
// Place here your custom code!

// Do not touch the following lines
// This loads all plugins defined in routes
// define your routes in one of these
fastify.register(AutoLoad, {
dir: path.join(__dirname, 'routes'),
options: Object.assign({}, opts),
});
};

module.exports.options = options;
28 changes: 28 additions & 0 deletions examples/mounts/default-ssl.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
server {
listen 0.0.0.0:8443 ssl;
listen 0.0.0.0:8080;
server_name localhost;

ssl_certificate /etc/lando/certs/cert.crt;
ssl_certificate_key /etc/lando/certs/cert.key;

ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;

ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
1 change: 1 addition & 0 deletions examples/mounts/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>HELLO THERE!</h1>
Loading

0 comments on commit 09a31de

Please sign in to comment.