我有Angular
个Cypress
应用。我想在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
很遗憾,我无法使用内置的npm
映像,因为Cypress
需要安装一些其他库。这就是为什么我开始建立自己的形象的原因。
# 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
当我将应用程序复制到容器中时,它起作用了。但是我必须再次安装依赖项,因此我决定将COPY
替换为VOLUME
,以加快整个过程。
# 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日志(最新的优先):
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) ...
...
我做错了什么?
答案 0 :(得分:2)
使用命令RUN时,将在容器的构建期间启动命令。就像您执行的String createdAt = (String) attrs.get("whenCreated").get();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
//sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
Date cre = null;
try {
cre = sdf.parse(createdAt);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
sfd = new SimpleDateFormat("yyyy-MM-dd");
mp.put("ldap_created_at", sdf.format(cre) );
一样:运行软件包的安装。
构建自定义Cloud Builder时,无法在容器构建时设置卷。因此,您不必运行命令。
将apt-get
末尾替换为RUN
,它定义了执行容器时要运行的默认命令。
然后,当您使用容器时,不要忘记指定体积