OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Google Cloud Build with Dockerfile and copy files

  • Thread starter Thread starter Nikita Davydov
  • Start date Start date
N

Nikita Davydov

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

My Dockerfile:

Code:
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:

Code:
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
<p>I've got the problem during setting up deploying using cloudbuild and dockerfile.</p>
<p>My <code>Dockerfile</code>:</p>
<pre><code>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"]
</code></pre>
<p>My <code>cloudbuild.yaml</code>:</p>
<pre><code>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"
</code></pre>
<p>Problem is that copied files <code>.env</code> and <code>app.yaml</code> are not presented in <code>workspace</code>
I don't know why cloudbuild ignore these files from image, because I've printed <code>ls -a</code> 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</p>
Continue reading...
 

Latest posts

Online statistics

Members online
0
Guests online
5
Total visitors
5
Top