dnephin / dobi

A build automation tool for Docker applications
https://dnephin.github.io/dobi/
Apache License 2.0
309 stars 36 forks source link

compose:down does not resolve dependencies #133

Open Enteee opened 6 years ago

Enteee commented 6 years ago
$ dobi --version
dobi version 0.11 (build: 0027fb7, date: Thu Apr 19 03:22:59 UTC 2018)

Dobi does not seem to resolve dependencies for compose-jobs when running the :down-task.

Example

dobi.yaml

env=env/base:
  variables: [
    "DOCKER_REGISTRY=your.local.docker.registry.com",
    "YUM_REPO_LOCAL_PORT=8081",
    "TAG=latest",
  ]

image=image/nginx:
  depends: [
    "env/base",
  ]
  image: "{env.DOCKER_REGISTRY}/nginx"
  context: "nginx"
  args:
    base_image: "nginx:1.13.12-alpine"
  tags: [
    "{env.TAG}",
  ]

compose=compose/base:
  depends: [
    "env/base",
    "image/nginx",
  ]
  files: [
    "docker-compose.yml"
  ]

nginx/Dockerfile

ARG base_image
FROM ${base_image}

docker-compose.yml

version: '3'

services:
  yum-local-repository:
    image: "${DOCKER_REGISTRY}/nginx"
    ports:
      - "${YUM_REPO_LOCAL_PORT}:80"

Usage

$ dobi compose/base
[WARN] meta.project is not set. Using default "dobiproject".
[env:set env/base] Done
[env:set env/base] Done
Step 1/2 : ARG base_image
Step 2/2 : FROM ${base_image}
 ---> ebe2c7c61055
Successfully built ebe2c7c61055
Successfully tagged your.local.docker.registry.com/nginx:latest
[image:build image/nginx] your.local.docker.registry.com/nginx Created
[compose:up compose/base] docker-compose.yml project up
Starting dobiproject-ente_yum-local-repository_1 ... done
[compose:up compose/base] docker-compose.yml Done
[compose:up compose/base] docker-compose.yml project stop
Stopping dobiproject-ente_yum-local-repository_1 ... done
[compose:up compose/base] docker-compose.yml Done

$ dobi compose/base:detach
[WARN] meta.project is not set. Using default "dobiproject".
[env:set env/base] Done
[env:set env/base] Done
[image:build image/nginx] your.local.docker.registry.com/nginx is fresh
[compose:detach compose/base] docker-compose.yml project up
Starting dobiproject-ente_yum-local-repository_1 ... done
[compose:detach compose/base] docker-compose.yml Done

$ curl localhost:8081
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

$ dobi compose/base:down
[WARN] meta.project is not set. Using default "dobiproject".
[compose:down compose/base] docker-compose.yml project down
WARNING: The DOCKER_REGISTRY variable is not set. Defaulting to a blank string.
WARNING: The YUM_REPO_LOCAL_PORT variable is not set. Defaulting to a blank string.
ERROR: The Compose file './docker-compose.yml' is invalid because:
services.yum-local-repository.ports is invalid: Port ranges don't match in length
[ERROR] failed to execute task "compose/base:down": exit status 1
dnephin commented 6 years ago

Thanks for the bug report!

One workaround (which is definitely not great) is to create an alias for compose/base:down and make env/base run first:

alias=cleanup:
  tasks: ['env/base', 'compose/base:down']

I think that should work.

The solution for this is not trivial, I think maybe env needs to be declared separately from other resources since it behaves differently. I need to think about it some more.