Creating volume in custom Docker image on GCP causing error

Viewed 385

I have Angular app with Cypress. I wanted to create a simple pipeline configuration on Google Cloud Build.

images:
  - 'gcr.io/$PROJECT_ID/e2e-tests'

steps:
  # Install node_modules
  - name: node:10.16.3
    entrypoint: npm
    args: ['ci']
    id: install

  # Run linters
  - name: node:10.16.3
    entrypoint: npm
    args: ['run', 'lint']
    id: lint
    waitFor:
      - install

  # Run unit tests
  - name: node:10.16.3
    entrypoint: npm
    args: ['test']
    id: test
    waitFor:
      - lint

  # Run e2e tests
  - name: 'gcr.io/cloud-builders/docker'
    args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/e2e-tests', '-f', 'docker/cypress/Dockerfile', '.' ]
    id: e2e
    waitFor:
      - lint

  # Build app for prod
  - name: node:10.16.3
    entrypoint: npm
    args: ['build']
    id: build
    waitFor:
      - test
      - e2e

Unfortunately I cannot use built-in npm image, because Cypress needs some additional libs installed. That's why I started building my own image.

# THIS ONE IS WORKING

FROM node:lts

RUN apt-get update && \
  apt-get install -y \
    libgtk2.0-0 \
    libnotify-dev \
    libgconf-2-4 \
    libnss3 \
    libxss1 \
    libasound2 \
    xvfb

ENV PATH /app/node_modules/.bin:$PATH
ENV CI=1

WORKDIR /app
COPY . /app

RUN npm ci
RUN npm run e2e:ci

It worked when I was copying the app into the container. But I have to install dependencies once again, so I decided to replace COPY with VOLUME to fast up the whole process.

# THIS ONE GETS AN ERROR LISTED BELOW

FROM node:lts

RUN apt-get update && \
  apt-get install -y \
    libgtk2.0-0 \
    libnotify-dev \
    libgconf-2-4 \
    libnss3 \
    libxss1 \
    libasound2 \
    xvfb

ENV PATH /app/node_modules/.bin:$PATH
ENV CI=1

VOLUME . /app

WORKDIR /app

RUN npm run e2e:ci

GCB log (newest first):

OCI runtime create failed: container_linux.go:345: starting container process caused "process_linux.go:430: container init caused \"apply apparmor profile: apparmor failed to apply profile: open /proc/self/attr/exec: no such file or directory\"": unknown
---> Running in be2a7992ad86
Step 7/7 : RUN npm run e2e:ci
---> 4fc9a0a86172
Removing intermediate container 53ee0d15063f
---> Running in 53ee0d15063f
Step 6/7 : WORKDIR /app
---> dd7298b536a0
Removing intermediate container 7f15a02f79e2
---> Running in 7f15a02f79e2
Step 5/7 : VOLUME . /app
---> 63124861eb3d
Removing intermediate container 28231f3bbf16
---> Running in 28231f3bbf16
Step 4/7 : ENV CI=1
---> a2563c01781f
Removing intermediate container 1579023b86b1
---> Running in 1579023b86b1
Step 3/7 : ENV PATH /app/node_modules/.bin:$PATH
---> d765db9e3ddf
Removing intermediate container a0ac5fd5da98
Processing triggers for libc-bin (2.24-11+deb9u4) ...
Setting up notification-daemon (3.20.0-1+b1) ...
Setting up libgtk-3-bin (3.22.11-1) ...
Setting up libgtk-3-0:amd64 (3.22.11-1) ...
Setting up librest-0.7-0:amd64 (0.8.0-2) ...
...

What I'm doing wrong?

1 Answers

When you use the command RUN, you launch a command during the BUILD of the container. Like the apt-get that you perform: you run the installation of the packages.

When you build your custom Cloud Builder, you can't set a volume at the container build time. Thereby, you don't have to RUN the command.

Replace the RUN at the end by ENTRYPOINT which defines the default command to run when the container is executed.

Then, when you use your container, don't forget to specify the volume

Related