refactor: download docker binary instead of installing with apk to reduce size of worker image
This commit is contained in:
parent
2ef93c50eb
commit
60e28fd6b2
4 changed files with 41 additions and 7 deletions
|
@ -60,7 +60,6 @@ services:
|
|||
context: .
|
||||
dockerfile: ./packages/worker/Dockerfile
|
||||
container_name: tipi-worker
|
||||
user: root
|
||||
healthcheck:
|
||||
test: ['CMD', 'curl', '-f', 'http://localhost:3000/healthcheck']
|
||||
interval: 5s
|
||||
|
|
|
@ -3,21 +3,39 @@ ARG ALPINE_VERSION="3.18"
|
|||
|
||||
FROM node:${NODE_VERSION}-alpine${ALPINE_VERSION} AS node_base
|
||||
|
||||
# ---- BUILDER BASE ----
|
||||
FROM node_base AS builder_base
|
||||
|
||||
RUN npm install pnpm -g
|
||||
RUN apk add curl
|
||||
|
||||
# ---- RUNNER BASE ----
|
||||
FROM node_base AS runner_base
|
||||
|
||||
# Install docker
|
||||
RUN apk upgrade --update-cache --available && \
|
||||
apk add openssl git docker docker-cli-compose curl && \
|
||||
rm -rf /var/cache/apk/*
|
||||
RUN apk add curl openssl git && rm -rf /var/cache/apk/*
|
||||
|
||||
ARG NODE_ENV="production"
|
||||
|
||||
# ---- BUILDER ----
|
||||
FROM builder_base AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
ARG TARGETARCH
|
||||
ENV TARGETARCH=${TARGETARCH}
|
||||
|
||||
RUN echo "Building for ${TARGETARCH}"
|
||||
|
||||
RUN if [ "${TARGETARCH}" = "arm64" ]; then \
|
||||
curl -L -o docker-binary "https://github.com/docker/compose/releases/download/v2.23.1/docker-compose-linux-aarch64"; \
|
||||
elif [ "${TARGETARCH}" = "amd64" ]; then \
|
||||
curl -L -o docker-binary "https://github.com/docker/compose/releases/download/v2.23.1/docker-compose-linux-x86_64"; \
|
||||
else \
|
||||
echo "Unsupported architecture"; \
|
||||
fi
|
||||
|
||||
RUN chmod +x docker-binary
|
||||
|
||||
COPY ./pnpm-lock.yaml ./
|
||||
COPY ./pnpm-workspace.yaml ./
|
||||
COPY ./patches ./patches
|
||||
|
@ -34,6 +52,7 @@ COPY ./packages/worker/assets ./packages/worker/assets
|
|||
|
||||
RUN pnpm -r build --filter @runtipi/worker
|
||||
|
||||
# ---- RUNNER ----
|
||||
FROM runner_base AS app
|
||||
|
||||
WORKDIR /app
|
||||
|
@ -42,6 +61,7 @@ ENV NODE_ENV=production
|
|||
|
||||
COPY --from=builder /app/packages/worker/dist .
|
||||
COPY --from=builder /app/packages/worker/assets ./assets
|
||||
COPY --from=builder /app/docker-binary /usr/local/bin/docker-compose
|
||||
|
||||
CMD ["node", "index.js", "start"]
|
||||
|
||||
|
|
|
@ -5,9 +5,24 @@ FROM node:${NODE_VERSION}-alpine${ALPINE_VERSION} AS node_base
|
|||
|
||||
# Install docker
|
||||
RUN apk upgrade --update-cache --available && \
|
||||
apk add openssl git docker docker-cli-compose curl unzip && \
|
||||
apk add openssl git docker docker-cli-compose curl && \
|
||||
rm -rf /var/cache/apk/*
|
||||
|
||||
ARG TARGETARCH
|
||||
ENV TARGETARCH=${TARGETARCH}
|
||||
|
||||
RUN echo "Building for ${TARGETARCH}"
|
||||
|
||||
RUN if [ "${TARGETARCH}" = "arm64" ]; then \
|
||||
curl -L -o docker-binary "https://github.com/docker/compose/releases/download/v2.23.1/docker-compose-linux-aarch64"; \
|
||||
elif [ "${TARGETARCH}" = "amd64" ]; then \
|
||||
curl -L -o docker-binary "https://github.com/docker/compose/releases/download/v2.23.1/docker-compose-linux-x86_64"; \
|
||||
fi
|
||||
|
||||
RUN chmod +x docker-binary
|
||||
|
||||
RUN mv docker-binary /usr/local/bin/docker-compose
|
||||
|
||||
RUN npm install pnpm -g
|
||||
|
||||
WORKDIR /app
|
||||
|
|
|
@ -6,7 +6,7 @@ import { ROOT_FOLDER, STORAGE_FOLDER } from '@/config/constants';
|
|||
|
||||
const composeUp = async (args: string[]) => {
|
||||
logger.info(`Running docker compose with args ${args.join(' ')}`);
|
||||
const { stdout, stderr } = await execAsync(`docker compose ${args.join(' ')}`);
|
||||
const { stdout, stderr } = await execAsync(`docker-compose ${args.join(' ')}`);
|
||||
|
||||
if (stderr && stderr.includes('Command failed:')) {
|
||||
throw new Error(stderr);
|
||||
|
|
Loading…
Add table
Reference in a new issue