Equivalent of CircleCI 1.0 build_dir

configuration

#1

What is the CircleCI 2.0 equivalent of the 1.0 build_dir directive?

https://circleci.com/docs/1.0/configuration/

I have a Git repository which contains multiple Dockerfiles, and I’m currently doing this:

build_docker_image_base: &build_docker_image_base
    working_directory: /tmp/workspace
    docker:
        - image: docker:17.04.0-ce-git
    steps:
        - checkout
        - setup_remote_docker
        - run:
            name: Build the Docker Image
            command: |
                cd docker/docker-images/${IMAGE_NAME}
                make package
        - deploy:
            name: Publish a Docker Image
            command: |
                cd docker/docker-images/${IMAGE_NAME}
                make publish_branch

It would be nice if I could avoid the cd to set the correct working directory at the start of every command block.


#2

It’s working_directory


#3

How does working_directory work then? It’s super confusing. When you run the checkout step, it checks out the project wherever working_directory is set. Can you reset working_directory as a step somehow?


#4
build:
    working_directory: /tmp/workspace
    docker:
        - image: docker:17.04.0-ce-git
    steps:
        - checkout
        - setup_remote_docker
        - run:
            name: Build the Docker Image
            command: make package
            working_directory: docker/docker-images/image1
        - deploy:
            name: Publish a Docker Image
            command: make publish_branch
            working_directory: docker/docker-images/image1             

It’s worth noting that env vars probably won’t work where you had them in your initial post, but I haven’t personally tried it.


#5

Is it possible to set the working directory context for all the steps after the checkout, as was possible with build_dir? Setting the working_directory for every command isn’t really an improvement over just using cd.


#6

No. But you can do this;

        - run:
            name: Build the Docker Image
            command: make package && make publish_branch
            working_directory: docker/docker-images/image1

#7

I’m really unclear on the reasoning behind having the working directory be set before the checkout step. The directory the code is put into is almost always irrelevant, but the working directory within the code tree is much more frequently relevant.

It makes more sense to me to have a top level build_dir equivalent which sets the working directory relative to the directory where the code is checked out.

EG:

build:
    build_dir: docker/docker-images/image1
    docker:
        - image: docker:17.04.0-ce-git
    steps:
        - checkout
        - setup_remote_docker
        - run:
            name: Build the Docker Image
            command: make package
        - deploy:
            name: Publish a Docker Image
            command: make publish_branch

I’m not even sure checkout should be a step, something like this makes more sense to me:

build:
    checkout:
        checkout_path: /tmp/workspace
        build_dir: docker/docker-images/image1
    docker:
        - image: docker:17.04.0-ce-git
    steps:
        - setup_remote_docker
        - run:
            name: Build the Docker Image
            command: make package
        - deploy:
            name: Publish a Docker Image
            command: make publish_branch

#8

In any case, thanks for the answer, I’ll use the working_directory run subkey.


#9

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.