Skip to content

Commit

Permalink
reboot l337 tests part 4
Browse files Browse the repository at this point in the history
  • Loading branch information
pirog committed Sep 8, 2023
1 parent 1b60582 commit fd812cd
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 50 deletions.
40 changes: 20 additions & 20 deletions examples/l337/.lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ services:
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: 1
BOB: 5
scanner: false
working_dir: "/tmp"
web:
api: 4
primary: true
Expand All @@ -45,6 +46,7 @@ services:
volumes:
- "./:/site"
- "my-data:/data"
- "./file1:/file-ro:ro"
ports:
- 8888
moreHttpPorts:
Expand All @@ -53,7 +55,7 @@ services:
# image features
image-1:
api: 4
image: "nginx:1.21"
image: "nginx:1.21.6"
image-2:
api: 4
image: "./images/nginx/Dockerfile"
Expand All @@ -63,25 +65,23 @@ services:
# also test weird indentation and casing
FROM nginx:1.20
copy file1 /file1
# image-4:
# api: 4
# working_dir: "/tmp"
# image:
# imagefile: "nginx:1.21"
# tag: "lando/nginx:powerman-5000"
# image-5:
# api: 4
# working_dir: "/tmp"
# image:
# dockerfile: "./images/nginx/Dockerfile"
# image-6:
# api: 4
# working_dir: "/tmp"
# image:
# imagefile: |
# FROM nginx:1.21
# ENV SPOCK NIMOY
ENV SERVICE image-3
image-4:
api: 4
image:
imagefile: "nginx:1.21.5"
tag: "lando/nginx:powerman-5000"
image-5:
api: 4
image:
dockerfile: "./images/nginx/Dockerfile2"
image-6:
api: 4
image:
imagefile: |
FROM nginx:1.21.6
ENV SERVICE image-6
WORKDIR /usr/share/nginx/html
# # context features
# context-1:
Expand Down
86 changes: 57 additions & 29 deletions examples/l337/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,18 @@ cat $(lando info -s db --path "[0].image" --format json | tr -d '"') | grep "ENV
lando info -s web | grep api: | grep 4
lando info -s web | grep type: | grep l337
lando info -s web | grep lastBuild: | grep never
lando info -s web | grep -z image: | grep Imagefile
lando info -s web | grep -z image: | grep /Imagefile
lando info -s web | grep primary: | grep true
lando info -s web | grep appMount: | grep /site
lando info -s web | grep user: | grep nginx
lando info -s web | grep hostnames: | grep web.l337.internal
cat $(lando info -s web --path "[0].image" --format json | tr -d '"') | grep ENV | grep SERVICE | grep web
lando info -s image-1 | grep image: | grep nginx:1.21.6
lando info -s image-2 | grep -z image: | grep core/examples/l337/images/nginx/Dockerfile
lando info -s image-3 | grep -z image: | grep /Imagefile
lando info -s image-4 | grep image: | grep nginx:1.21.5
lando info -s image-5 | grep -z image: | grep core/examples/l337/images/nginx/Dockerfile2
lando info -s image-6 | grep -z image: | grep /Imagefile

# should start again successfully
lando start
Expand All @@ -57,7 +63,22 @@ lando rebuild -y

# should have the correct info when built
lando info -s db | grep lastBuild: | grep succeeded
lando info -s db | grep tag: | grep "lando/l337\-" | grep "\-db:latest"
lando info -s web | grep lastBuild: | grep succeeded
lando info -s web | grep tag: | grep "lando/l337\-" | grep "\-web:latest"

lando info -s image-1 | grep tag: | grep "lando/l337\-" | grep "\-image-1:latest"
lando info -s image-1 | grep lastBuild: | grep succeeded
lando info -s image-2 | grep tag: | grep "lando/l337\-" | grep "\-image-2:latest"
lando info -s image-2 | grep lastBuild: | grep succeeded
lando info -s image-3 | grep tag: | grep "lando/l337\-" | grep "\-image-3:latest"
lando info -s image-3 | grep lastBuild: | grep succeeded
lando info -s image-4 | grep tag: | grep "lando/l337\-" | grep "\-image-4:latest"
lando info -s image-4 | grep lastBuild: | grep succeeded
lando info -s image-5 | grep tag: | grep "lando/l337\-" | grep "\-image-5:latest"
lando info -s image-5 | grep lastBuild: | grep succeeded
lando info -s image-6 | grep tag: | grep "lando/l337\-" | grep "\-image-6:latest"
lando info -s image-6 | grep lastBuild: | grep succeeded

# should use web as the primary service for tooling and events
lando ssh -c "env" | grep SERVICE | grep web
Expand All @@ -77,35 +98,42 @@ docker volume ls | grep l337_my-data

# should allow top level network creation
docker network ls | grep l337_my-network
```

# should allow short form registry image
lando ssh -s image-1 -c "env" | grep NGINX_VERSION | grep 1.21.
lando ssh -s image-1 -c "env" | grep PIKE | grep MOUNT

# should allow short form dockerfile
lando ssh -s image-2 -c "env" | grep NGINX_VERSION | grep 1.19.
lando ssh -s image-2 -c "env" | grep KIRK | grep SHATNER

# should allow short form docker instructions
lando ssh -s image-3 -c "env" | grep NGINX_VERSION | grep 1.20.
lando ssh -s image-3 -c "env" | grep SPOCK | grep NIMOY

# should allow long form registry image
lando ssh -s image-4 -c "env" | grep NGINX_VERSION | grep 1.21.
lando ssh -s image-4 -c "env" | grep PIKE | grep MOUNT

# should allow long form dockerfile
lando ssh -s image-5 -c "env" | grep NGINX_VERSION | grep 1.19.
lando ssh -s image-5 -c "env" | grep KIRK | grep SHATNER

# should allow long form docker instructions
lando ssh -s image-6 -c "env" | grep NGINX_VERSION | grep 1.20.
lando ssh -s image-6 -c "env" | grep SPOCK | grep NIMOY

# should allow interoperability with build and dockerfile
lando ssh -s image-7 -c "env" | grep NGINX_VERSION | grep 1.21.
lando ssh -s image-7 -c "env" | grep SPOCK | grep NIMOY
# should handle different image build formats
lando env | grep SERVICE | grep web
lando env --service db | grep SERVICE | grep db
lando env --service image-1 | grep NGINX_VERSION | grep "1.21.6"
lando env --service image-2 | grep SERVICE | grep image-2
lando env --service image-3 | grep SERVICE | grep image-3
lando env --service image-4 | grep NGINX_VERSION | grep "1.21.5"
lando env --service image-5 | grep SERVICE | grep image-5
lando env --service image-6 | grep SERVICE | grep image-6

# should handle COPY instructions correctly
lando ssh --service web -c "curl localhost:8888" | grep "look you wanna be L337"
lando ssh --service db -c "stat /thing"
lando ssh --service db -c "stat /itworked"
lando ssh --service image-2 -c "stat /file10"
lando ssh --service image-3 -c "stat /file1"

# should run in working_dir if appMount is not set
lando pwd --service db | grep /tmp
lando ssh --service db -c "pwd" | grep /tmp
cd folder
lando pwd --service db | grep -w /tmp
lando ssh --service db -c "pwd" | grep /tmp
cd ..

# should run in image working_dir as fallback
lando pwd --service image-1 | grep -w /
lando ssh --service image-1 -c "pwd" | grep -w /
lando pwd --service image-6 | grep /usr/share/nginx/html
lando ssh --service image-6 -c "pwd" | grep /usr/share/nginx/html

# should correctly mount read-only volumes
lando ssh -c "test -r /file-ro"
lando ssh -c "test -w /file-ro" || echo $? | grep 1
```

Destroy tests
-------------
Expand Down
1 change: 1 addition & 0 deletions examples/l337/images/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
FROM nginx:1.19

ENV KIRK SHATNER
ENV SERVICE image-2

COPY file10 /file10
6 changes: 6 additions & 0 deletions examples/l337/images/nginx/Dockerfile2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM nginx:1.23

ENV KIRK SHATNER
ENV SERVICE image-5

COPY file10 /file10
2 changes: 1 addition & 1 deletion plugins/lando-services-v4/lib/docker-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class DockerEngine extends Dockerode {

// call the parent
// @TODO: consider other opts? https://docs.docker.com/engine/api/v1.43/#tag/Image/operation/ImageBuild args?
this.debug('building image %o with %o', tag, fs.readdirSync(context));
this.debug('building image %o from %o', tag, context);
super.buildImage({context, src: fs.readdirSync(context)}, {forcerm: true, t: tag}, callbackHandler);

// make this a hybrid async func and return
Expand Down
1 change: 1 addition & 0 deletions plugins/lando-services-v4/lib/l337-v4.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ class ComposeServiceV4 {
const instructions = Object.values(steps);
// unshift whatever we end up with in #data.from to the front of the instructions
instructions.unshift(this.#data.imageInstructions);
instructions.unshift(`# Dockerfile generated by Lando`);
// map instructions to imagefile content
const content = instructions.join('\n');
// @TODO: generic imagefile validation/linting/etc?or error
Expand Down

0 comments on commit fd812cd

Please sign in to comment.