Skip to content

Commit

Permalink
perf: smaller multiarch docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
mxsdev committed Sep 20, 2024
1 parent 66b62dc commit 18f1352
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 24 deletions.
13 changes: 2 additions & 11 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
CMD ["/app/localsandbox", "run"]
71 changes: 71 additions & 0 deletions build.log
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 18f1352

Please sign in to comment.