我一直在使用带有cloudbuild.yaml和Dockerfile的Google Cloud Build。你可以在下面找到文件:
cloudbuild.yaml
steps:
- name: 'gcr.io/cloud-builders/docker'
entrypoint: 'bash'
args: ['-c', 'docker pull gcr.io/$PROJECT_ID/github.com/videoo-io/videoo-render:latest || exit 0']
- name: 'gcr.io/cloud-builders/docker'
args: [
'build',
'-t', 'gcr.io/$PROJECT_ID/github.com/videoo-io/videoo-render:latest',
'--cache-from', 'gcr.io/$PROJECT_ID/github.com/videoo-io/videoo-render:latest',
'.'
]
images: ['gcr.io/$PROJECT_ID/github.com/videoo-io/videoo-render:latest']
timeout: 7200s
Dockerfile:
FROM --platform=amd64 ubuntu:22.10
# Use baseimage-docker's init system.
# CMD ["/sbin/my_init"]
ENV GCSFUSE_REPO gcsfuse-stretch
RUN apt-get update && apt-get install --yes --no-install-recommends
ca-certificates
curl
gnupg
&& echo "deb http://packages.cloud.google.com/apt $GCSFUSE_REPO main"
| tee /etc/apt/sources.list.d/gcsfuse.list
&& curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
&& apt-get update
&& apt-get install --yes gcsfuse
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
EXPOSE 80
RUN
sed -i 's/# (.*multiverse$)/1/g' /etc/apt/sources.list &&
apt-get update &&
apt-get -y upgrade &&
apt-get install -y build-essential &&
apt-get install -y gcc &&
apt-get install -y software-properties-common &&
apt install -y cmake &&
apt-get install -y make &&
apt-get install -y clang &&
apt-get install -y mesa-common-dev &&
apt-get install -y git &&
apt-get install -y xorg-dev &&
apt-get install -y nasm &&
apt-get install -y xvfb &&
apt-get install -y byobu curl git htop man unzip vim wget &&
rm -rf /var/lib/apt/lists/*
# Update and upgrade repo
RUN apt-get update -y -q && apt-get upgrade -y -q
COPY . /app
RUN cd /app
RUN ls -la
# Technicly speaking we must be inside the projects directory now.
# DO NOT FORGET to go back to this directory when working.
# CMD bash premake.sh
# Set environment variables.
ENV HOME /root
ENV WDIR /app
# Define working directory.
WORKDIR /app
ARG CACHEBUST=1
RUN cd /app/lib/glfw && cmake -G "Unix Makefiles" && make && apt-get install libx11-dev
RUN apt-cache policy libxrandr-dev
RUN apt install libxrandr-dev
RUN cd /app/lib/ffmpeg && ./configure && make && make install
RUN cmake . && make
# Define default command.
CMD ["bash"]
当Cloud Build通过Dockerfile命令构建时,只有一些命令被缓存。例如,apt-install命令被缓存:
Step #1: Step 3/19 : RUN apt-get update && apt-get install --yes --no-install-recommends ca-certificates curl gnupg && echo "deb http://packages.cloud.google.com/apt $GCSFUSE_REPO main" | tee /etc/apt/sources.list.d/gcsfuse.list && curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - && apt-get update && apt-get install --yes gcsfuse && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
Step #1: ---> Using cache
Step #1: ---> 57af7779364e
但以下内容未缓存:
Step #1: Step 14/19 : RUN cd /app/lib/glfw && cmake -G "Unix Makefiles" && make && apt-get install libx11-dev
Step #1: ---> Running in 167e30a29720
Step #1: CMake Warning:
Step #1: No source or binary directory provided. Both will be assumed to be the
Step #1: same as the current working directory, but note that this warning will
Step #1: become a fatal error in future CMake releases.
Step #1:
Step #1:
Step #1: -- The C compiler identification is GNU 11.3.0
Step #1: -- Detecting C compiler ABI info
Step #1: -- Detecting C compiler ABI info - done
Step #1: -- Check for working C compiler: /usr/bin/cc - skipped
Step #1: -- Detecting C compile features
Step #1: -- Detecting C compile features - done
And the following is not cached as well :
Step #1: Step 17/19 : RUN cd /app/lib/ffmpeg && ./configure && make && make install
Step #1: ---> Running in cafb9a07e2bc
Step #1: install prefix /usr/local
Step #1: source path .
Step #1: C compiler gcc
Step #1: C library glibc
Step #1: ARCH x86 (generic)
Step #1: big-endian no
Step #1: runtime cpu detection yes
Step #1: standalone assembly yes
Step #1: x86 assembler nasm
为什么这些RUN命令中的一些被缓存,而另一些没有被缓存?
我不确定这是否与云构建有关,它看起来与docker层有关。
如果一个层最终根据您缓存的内容生成不同的哈希。。即使命令看起来相同,它也将被视为一个新层。
我认为接下来的几层也在重建中。