docker command substitution fails on gitlab



  • I am trying to run the following command as part of a deployment in Gitlab.

    TIMESTAMP=$(date +%s) docker stack deploy --with-registry-auth --compose-file $(`printf "docker-compose.%s.unimark.yaml" "$SRV_DEPLOY_ENV"`) unimark`
    

    I am getting the following error. I am not sure what is going wrong here.

    /bin/sh: eval: line 332: docker-compose.demo.unimark.yaml: not found
    "docker stack deploy" requires exactly 1 argument.
    See 'docker stack deploy --help'.
    Usage:  docker stack deploy [OPTIONS] STACK
    Deploy a new stack or update an existing stack
    

    I also tried

    DOCKER_COMPOSE_DEPLOY_FILE=`printf "docker-compose.%s.unimark.yaml" "$SRV_DEPLOY_ENV"`
    

    TIMESTAMP=$(date +%s) docker stack deploy --with-registry-auth --compose-file $($DOCKER_COMPOSE_DEPLOY_FILE) unimark`

    the same error saying docker-compose file cannot be found. I checked and the file is there in the same directory. Not sure if it has to do with some bash vs sh issue.



  • I think this is a problem with https://wiki.bash-hackers.org/syntax/expansion/cmdsubst .

    $(`printf "docker-compose.%s.unimark.yaml" "$SRV_DEPLOY_ENV"`)
    

    or

    DOCKER_COMPOSE_DEPLOY_FILE=`printf "docker-compose.%s.unimark.yaml" 
    "$SRV_DEPLOY_ENV"`
    $($DOCKER_COMPOSE_DEPLOY_FILE)
    

    To bash is interpreted the same: please execute the command that is the result of this nested command.

    Removing the backtick in the first instance or removing the parenthesis in the second one should do the trick.




Suggested Topics