skip to Main Content

I’ve got the problem during setting up deploying using cloudbuild and dockerfile.

My Dockerfile:

FROM python:3.8

ARG ENV
ARG NUM_WORKERS
ENV PORT=8080
ENV NUM_WORKERS=$NUM_WORKERS


RUN pip install poetry
COPY pyproject.toml poetry.lock ./

RUN poetry config virtualenvs.create false && 
    poetry install --no-dev

COPY ./.env.$ENV /workspace/.env
COPY ./app-$ENV.yaml /workspace/app.yaml
COPY . /workspace

ENTRYPOINT ["./entrypoint.sh"]

My cloudbuild.yaml:

steps:
  - name: 'gcr.io/cloud-builders/docker'
    entrypoint: 'bash'
    args:
      - '-c'
      - |
        docker pull gcr.io/$PROJECT_ID/my-repo:$BRANCH_NAME || exit 0
  - name: 'gcr.io/cloud-builders/docker'
    args: [
      'build',
      '-t',
      'gcr.io/$PROJECT_ID/my-repo:$BRANCH_NAME',
      '--cache-from',
      'gcr.io/$PROJECT_ID/my-repo:$BRANCH_NAME',
      '--build-arg', 'ENV=develop',
      '--build-arg', 'NUM_WORKERS=2',
      '.'
    ]

  - name: 'gcr.io/cloud-builders/docker'
    args: ['push', 'gcr.io/$PROJECT_ID/my-repo:$BRANCH_NAME']

  - name: 'gcr.io/$PROJECT_ID/my-repo:$BRANCH_NAME'
    id: RUN-LINTERS
    entrypoint: sh
    args: ['scripts/linters.sh']

  - name: gcr.io/cloud-builders/docker
    id: START-REDIS
    args: ['run', '-d', '--network=cloudbuild', '--name=redisdb', 'redis']

  - name: 'gcr.io/$PROJECT_ID/my-repo:$BRANCH_NAME'
    id: RUN-TESTS
    entrypoint: sh
    args: ['scripts/run_tests.sh']
    env:
      - 'REDIS_HOST=redis://redisdb'
      - 'DATASTORE_EMULATOR_HOST=datastore:8081'
    waitFor:
      - START-REDIS
      - START-DATASTORE-EMULATOR

  - name: gcr.io/cloud-builders/docker
    id: SHUTDOWN-REDIS
    args: ['rm', '--force', 'redisdb']

  - name: gcr.io/cloud-builders/docker
    id: SHUTDOWN-DATASTORE_EMULATOR
    args: ['rm', '--force', 'datastore']

  - name: 'gcr.io/cloud-builders/gcloud'
    id: DEPLOY
    args:
      - "app"
      - "deploy"
      - "--image-url"
      - 'gcr.io/$PROJECT_ID/my-repo:$BRANCH_NAME'
      - "--verbosity=debug"
images: ['gcr.io/$PROJECT_ID/my-repo:$BRANCH_NAME']
timeout: "1000s"

Problem is that copied files .env and app.yaml are not presented in workspace
I don’t know why cloudbuild ignore these files from image, because I’ve printed ls -a and have seen that files are copied properly during build, but they disappear during run-tests stage and also I can’t deploy without app.yaml
Any help pleaseee

2

Answers


  1. Chosen as BEST ANSWER

    To fix it I've just copied it in cloudbuild before build

    - name: 'gcr.io/cloud-builders/gcloud'
      id: MOVE-DOTENV-APP-YAML
      entrypoint: bash
      args:
        - '-e'
        - '-c'
        - |
          cp app-$_ENVIRONMENT.yaml app.yaml
          cp .env.$_ENVIRONMENT .env
    

  2. You need to set WORKDIR /workspace in Dockerfile.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search