#Yes, totally. Having said that, there's
1 messages · Page 1 of 1 (latest)
builderDir := builder.Directory("./")
packageDistDir := builder.Directory("./packages/backend/dist/")
runner := client.
Container().
From("registry.access.redhat.com/ubi9/nodejs-18-minimal").
WithUser("0").
WithWorkdir("/opt/app-root/src")
_, err = installRunner(runner).
WithUser("1001").
WithFile("/opt/app-root/src/package.json", builderDir.File("package.json")).
WithFile("/opt/app-root/src/yarn.lock", builderDir.File("yarn.lock")).
WithFile("/opt/app-root/src/skeleton.tar.gz", packageDistDir.File("skeleton.tar.gz")).
WithExec([]string{"tar", "xzf", "skeleton.tar.gz"}).
WithExec([]string{"rm", "skeleton.tar.gz"}).
WithExec([]string{"yarn", "install", "--frozen-lockfile", "--production", "--network-timeout", "600000"}).
WithExec([]string{"yarn", "cache", "clean"}).
WithFile("/opt/app-root/src/bundle.tar.gz", packageDistDir.File("bundle.tar.gz")).
WithExec([]string{"tar", "xzf", "bundle.tar.gz"}).
WithExec([]string{"rm", "bundle.tar.gz"}).
WithFile("/opt/app-root/src/app-config.yaml", builderDir.File("app-config.yaml")).
WithExec([]string{"fix-permissions", "./"}).
WithEntrypoint([]string{"node", "packages/backend", "--config", "app-config.yaml"}).
Export(ctx, "/tmp/my-app2.tar")
docker file
# Stage 1 - Install dependencies
FROM registry.access.redhat.com/ubi9/nodejs-18 AS deps
USER 0
# Install yarn
RUN \
curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | tee /etc/yum.repos.d/yarn.repo && \
dnf install -y yarn && \
dnf install -y sqlite zlib-devel brotli brotli-devel && \
dnf clean all
COPY ./package.json ./yarn.lock ./
COPY ./packages ./packages
COPY ./plugins ./plugins
# Remove all files except package.json
RUN find packages -mindepth 2 -maxdepth 2 \! -name "package.json" -exec rm -rf {} \+
RUN yarn install --frozen-lockfile --network-timeout 600000
# Stage 2 - Build packages
FROM registry.access.redhat.com/ubi9/nodejs-18 AS build
USER 0
# Install yarn
RUN \
curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | tee /etc/yum.repos.d/yarn.repo && \
dnf install -y sqlite zlib-devel brotli brotli-devel && \
dnf install -y yarn
COPY . .
COPY --from=deps /opt/app-root/src .
RUN yarn tsc
RUN yarn build:backend
# Stage 3 - Build the actual backend image and install production dependencies
FROM registry.access.redhat.com/ubi9/nodejs-18-minimal AS runner
USER 0
ENV HTTP_PROXY $HTTP_PROXY
ENV HTTPs_PROXY $HTTPs_PROXY
# Install yarn
RUN \
curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | tee /etc/yum.repos.d/yarn.repo && \
microdnf install -y sqlite zlib-devel brotli brotli-devel make yarn gcc-c++ python openssl-devel && \
yarn config set python /usr/bin/python3 && \
npm install -g node-gyp
# Install gzip for tar and clean up
RUN microdnf install -y gzip && microdnf clean all
# Switch to nodejs user
USER 1001
# Copy the installation dependencies from the build stage and context
COPY --from=build /opt/app-root/src/yarn.lock /opt/app-root/src/package.json /opt/app-root/src/packages/backend/dist/skeleton.tar.gz ./
RUN tar xzf skeleton.tar.gz && rm skeleton.tar.gz
# Install production dependencies
RUN yarn install --frozen-lockfile --production --network-timeout 600000 && yarn cache clean
# Copy the built packages from the build stage
COPY --from=build /opt/app-root/src/packages/backend/dist/bundle.tar.gz .
RUN tar xzf bundle.tar.gz && rm bundle.tar.gz
# Copy any other files that we need at runtime
COPY ./app-config.yaml .
# The fix-permissions script is important when operating in environments that dynamically use a random UID at runtime, such as OpenShift.
# The upstream backstage image does not account for this and it causes the container to fail at runtime.
RUN fix-permissions ./
CMD ["node", "packages/backend", "--config", "app-config.yaml"]
it looks like the yarn install is the part that brings in the biggest amount
Question: what does installRunner do? That's the main thing that's making me think there might be something happening there
func installRunner(container *dagger.Container) *dagger.Container {
return container.
WithExec([]string{"curl", "--silent", "--location", "https://dl.yarnpkg.com/rpm/yarn.repo", "-o", "/etc/yum.repos.d/yarn.repo"}).
WithExec([]string{"microdnf", "install", "-y", "yarn"}).
WithExec([]string{"microdnf", "install", "-y", "sqlite"}).
WithExec([]string{"microdnf", "install", "-y", "zlib-devel"}).
WithExec([]string{"microdnf", "install", "-y", "brotli"}).
WithExec([]string{"microdnf", "install", "-y", "brotli-devel"}).
WithExec([]string{"microdnf", "install", "-y", "make"}).
WithExec([]string{"microdnf", "install", "-y", "gcc-c++"}).
WithExec([]string{"microdnf", "install", "-y", "python"}).
WithExec([]string{"microdnf", "install", "-y", "openssl-devel"}).
WithExec([]string{"microdnf", "install", "-y", "gzip"}).
WithExec([]string{"yarn", "config", "set", "python", "/usr/bin/python3"}).
WithExec([]string{"yarn", "global", "add", "node-gyp"}).
WithExec([]string{"microdnf", "clean", "all"})
}
ok, I think I've found what's happening here.
In your dagger pipeline you have this for example:
WithExec([]string{"tar", "xzf", "skeleton.tar.gz"}).
WithExec([]string{"rm", "skeleton.tar.gz"}).
but then, In your Dockerfile you have this:
RUN tar xzf skeleton.tar.gz && rm skeleton.tar.gz
Those operations are not equivalent, because in the Dagger code you're still incrementing the layer size of the overlay FS. The equivalent in Dagger would be:
WithExec([]string{"sh", "-c", "tar xzf skeleton.tar.gz && rm skeleton.tar.gz"})
Same for all the other steps where you do something similar.