From 18f13524d2f32349667d4220365863da61bd065b Mon Sep 17 00:00:00 2001 From: charburgx Date: Thu, 19 Sep 2024 22:21:27 -0700 Subject: [PATCH] perf: smaller multiarch docker build --- .github/workflows/publish.yml | 13 +------ Dockerfile | 24 ++++++------ build.log | 71 +++++++++++++++++++++++++++++++++++ package.json | 2 +- 4 files changed, 86 insertions(+), 24 deletions(-) create mode 100644 build.log diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 5a1d2ae..b9d5d72 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -28,23 +28,14 @@ jobs: - name: Build run: npm run build:docker - - name: Build image - run: docker build -t localsandbox/localsandbox . - - name: Login to Docker Hub uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - - name: Publish image - run: docker push localsandbox/localsandbox:latest - - - name: Publish image with tag - run: | - docker tag localsandbox/localsandbox localsandbox/localsandbox:${{ steps.tag.outputs.tag }} - docker push localsandbox/localsandbox:${{ steps.tag.outputs.tag }} - + - name: Build image + run: docker buildx build --platform linux/amd64,linux/arm64 . -t localsandbox/localsandbox:latest --push bundle-cli: name: Build & Bundle CLI diff --git a/Dockerfile b/Dockerfile index e948d8c..44bcb24 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,22 @@ -FROM node:20-alpine +FROM mcr.microsoft.com/azure-cli -# Install python/pip -ENV PYTHONUNBUFFERED=1 -RUN apk add py3-pip -RUN apk add gcc musl-dev python3-dev libffi-dev openssl-dev cargo make -RUN pip install --upgrade --break-system-packages pip -RUN pip install --break-system-packages azure-cli - -RUN az --version +ARG TARGETARCH WORKDIR /app -COPY ./dist/scripts/cjs/* /app/ +COPY ./dist/binary/localsandbox-linux-${TARGETARCH} /app/localsandbox + +RUN /app/localsandbox --version + +COPY ./packages/azure-local-cli/azure_local_cli/__main__.py /app/__main__.py RUN mkdir -p /app/azl -COPY ./dist/binary/azl-alpine /app/azl/azl + +RUN echo "#!/bin/bash" > /app/azl/azl +RUN echo "PYTHONPATH=/usr/lib64/az/lib/python3.9/site-packages python3 /app/__main__.py \$@" >> /app/azl/azl +RUN chmod +x /app/azl/azl ENV PATH="/app/azl:${PATH}" RUN azl --version -CMD ["node", "/app/cli.js", "run"] \ No newline at end of file +CMD ["/app/localsandbox", "run"] \ No newline at end of file diff --git a/build.log b/build.log new file mode 100644 index 0000000..2550999 --- /dev/null +++ b/build.log @@ -0,0 +1,71 @@ +#0 building with "desktop-linux" instance using docker driver + +#1 [internal] load build definition from Dockerfile +#1 transferring dockerfile: 424B done +#1 DONE 0.0s + +#2 [internal] load metadata for mcr.microsoft.com/azure-cli:latest +#2 DONE 0.0s + +#3 [internal] load .dockerignore +#3 transferring context: 2B done +#3 DONE 0.0s + +#4 [1/7] FROM mcr.microsoft.com/azure-cli:latest@sha256:2d18d025d51e28e790855a8666fab5b7672f2aa62210bca3a75c1f3fd9b68e25 +#4 resolve mcr.microsoft.com/azure-cli:latest@sha256:2d18d025d51e28e790855a8666fab5b7672f2aa62210bca3a75c1f3fd9b68e25 done +#4 DONE 0.0s + +#5 [2/7] WORKDIR /app +#5 CACHED + +#6 [internal] load build context +#6 transferring context: 65.37MB 0.3s done +#6 DONE 0.3s + +#7 [3/7] COPY ./dist/binary/localsandbox-linux-amd64 /app/localsandbox +#7 DONE 0.2s + +#8 [4/7] RUN /app/localsandbox --version +#8 1.368 0.1.0 +#8 DONE 1.4s + +#9 [5/7] RUN mkdir -p /app/azl +#9 DONE 0.1s + +#10 [6/7] COPY ./dist/binary/azl-linux-amd64 /app/azl/azl +#10 DONE 0.0s + +#11 [7/7] RUN azl --version +#11 9.302 azure-cli 2.64.0 +#11 9.302 +#11 9.302 core 2.64.0 +#11 9.302 telemetry 1.1.0 +#11 9.302 +#11 9.302 Dependencies: +#11 9.302 msal 1.30.0 +#11 9.302 azure-mgmt-resource 23.1.1 +#11 9.302 +#11 9.302 Python location '/usr/bin/python3.9' +#11 9.302 Extensions directory '/root/.azure/cliextensions' +#11 9.302 +#11 9.302 Python (Linux) 3.9.19 (main, Aug 23 2024, 00:07:48) +#11 9.302 [GCC 11.2.0] +#11 9.302 +#11 9.302 Legal docs and information: aka.ms/AzureCliLegal +#11 9.302 +#11 9.302 +#11 9.302 Your CLI is up-to-date. +#11 DONE 9.5s + +#12 exporting to image +#12 exporting layers +#12 exporting layers 2.1s done +#12 exporting manifest sha256:4637d212deae92cdc0136ec6e2d9d3f84d29c17b98c2a7c395726fb3b64d7591 +#12 exporting manifest sha256:4637d212deae92cdc0136ec6e2d9d3f84d29c17b98c2a7c395726fb3b64d7591 done +#12 exporting config sha256:d136e68e2a004790878f92cb116e5af7c8356df6bbae3caa4d00d2f4a9033837 done +#12 exporting attestation manifest sha256:4eab0131c09b18278cb30dd0ecbb429d50e5e7f49a80e15d4a590153b8102bba done +#12 exporting manifest list sha256:26c5e7a3507e836e5c55aed1be21cde060483a8919976a85c7293aae7eb765e7 done +#12 naming to moby-dangling@sha256:26c5e7a3507e836e5c55aed1be21cde060483a8919976a85c7293aae7eb765e7 done +#12 DONE 2.2s + +View build details: docker-desktop://dashboard/build/desktop-linux/desktop-linux/jorhyc244tif5451v9w492cxa diff --git a/package.json b/package.json index ae4010f..b64dcab 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "dev:cli:watch": "tsx --watch ./scripts/cli.ts", "dev": "cross-env LOG_LEVEL=debug npm run dev:cli:watch run", "build": "npm run build:scripts:cjs", - "build:docker": "npm run build:scripts:cjs && GOOS=linux GOARCH=amd64 go build -o ./dist/binary/azl-alpine ./azl.go", + "build:docker": "npm run build:scripts:cjs && cross-env PKG_TARGET=linux-x64 npm run build:cli:localsandbox && mv ./dist/binary/localsandbox ./dist/binary/localsandbox-linux-amd64 && cross-env PKG_TARGET=linux-arm64 npm run build:cli:localsandbox && mv ./dist/binary/localsandbox ./dist/binary/localsandbox-linux-arm64", "build:esm": "tsup --config ./tsup.esm.config.ts && resolve-tspaths --out ./dist/esm && shx cp ./package.esm.json ./dist/esm/package.json", "build:cjs": "tsup --config ./tsup.cjs.config.ts && resolve-tspaths --out ./dist/cjs && shx cp ./package.cjs.json ./dist/cjs/package.json && renamer --find .d.cts --replace .d.ts ./dist/cjs/**/*.d.cts", "build:scripts:cjs": "tsup --config ./tsup.scripts.cjs.config.ts && shx cp ./package.cli.json ./dist/scripts/cjs/package.json",