Docker container changing between jobs

I’m completely sure I just have something wrong in my config.yml file, but I’m not sure what. Here’s the config:

orbs:
  gcp-cli: circleci/gcp-cli@1.0.0

version: 2.1

executors:
  main-executor:
    docker:
      - image: circleci/php:7.2-node-browsers
      - image: circleci/mysql:5.7-ram
        environment:
          - MYSQL_ROOT_PASSWORD=root

commands:
  setup-app-engine-config:
    description: "Generates the app.yaml file for App Engine deployment"
    parameters:
      environment:
        type: string
      app-url:
        type: string
      gcp-project-id:
        type: env_var_name
      db-username:
        type: env_var_name
      db-password:
        type: env_var_name
      db-connection-name:
        type: env_var_name
    steps:
      - run: >-
             php .circleci/set-environment-var.php app.yaml
             APP_ENV,<< parameters.environment >>
             APP_URL,<< parameters.app-url >>
             GCP_PROJECT_ID,${<< parameters.gcp-project-id >>}
             DB_USERNAME,${<< parameters.db-username >>}
             DB_PASSWORD,${<< parameters.db-password >>}
             DB_CONNECTION_NAME,${<< parameters.db-connection-name >>}

  setup-nova-auth:
    description: "Generates the auth.json file for Nova authentication"
    steps:
      - run: >-
             php .circleci/set-environment-var.php auth.json
             NOVA_USERNAME,${NOVA_USERNAME}
             NOVA_PASSWORD,${NOVA_PASSWORD}

jobs:
  build:
    executor: main-executor

    steps:
      - checkout

      - run:
          name:    Set up container
          command: |
                   sudo apt update
                   sudo docker-php-ext-configure pdo_mysql --with-pdo-mysql=mysqlnd
                   sudo docker-php-ext-install zip bcmath pdo_mysql
                   sudo apt-get install mysql-client

      # Download and cache dependencies
      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "composer.lock" }}
            # fallback to using the latest cache if no exact match is found
            - v1-dependencies-

      - run:
          name:    Set up & install composer
          command: |
                   composer config http-basic.nova.laravel.com ${NOVA_USERNAME} ${NOVA_PASSWORD}
                   composer install -n --prefer-dist

      - save_cache:
          key: v1-dependencies-{{ checksum "composer.lock" }}
          paths:
            - ./vendor
      - restore_cache:
          keys:
            - node-v1-{{ checksum "package-lock.json" }}
            - node-v1-

      # Install NPM packages
      - run: npm install
      - save_cache:
          key: node-v1-{{ checksum "package-lock.json" }}
          paths:
            - node_modules

      # prepare the database
      - run: mysqladmin create test --host="127.0.0.1" --user="root" --password="root"
      - run: php artisan migrate --env=testing --force

      # run tests
      - run: ./vendor/bin/phpunit

  deploy-dev:
    executor: main-executor

    steps:
      - setup-app-engine-config:
          environment:        development
          app-url:            example.com
          gcp-project-id:     DEV_GCP_PROJECT_ID
          db-username:        DEV_DB_USERNAME
          db-password:        DEV_DB_PASSWORD
          db-connection-name: DEV_DB_CONNECTION_NAME

      - setup-nova-auth

      - gcp-cli/install

      - gcp-cli/initialize:
          gcloud-service-key:  DEV_GCP_SERVICE_KEY
          google-compute-zone: us-central
          google-project-id:   giveio-dev

      - run: gcloud app deploy --project={$DEV_GCP_PROJECT_ID}

workflows:
  version: 2
  build-deploy:
    jobs:
      - build
      - deploy-dev:
          requires:
            - build
          filters:
            branches:
              only: develop

It gets to the setup-app-engine-config line and then throws an error:
Could not open input file: .circleci/set-environment-var.php

I connected to the container via SSH to see what was going on and found that the ~/project directory is completely empty. I thought using the same executor between jobs would keep everything in the same container? Not sure what I’m doing wrong here.

Thank you!

Turns out I just needed to make use of caching and workspaces.

Thanks, Internet, for being my rubber duck. :slight_smile:

1 Like

Quack quack :rubberduck:

1 Like

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