|
| 1 | +# This is a hack to setuo alternate architecture names |
| 2 | +# For this to work, it needs to be built using docker 'buildx' |
| 3 | +FROM ghcr.io/raonigabriel/coder-core:latest AS linux-amd64 |
| 4 | +ARG ALT_ARCH=x64 |
| 5 | + |
| 6 | +FROM ghcr.io/raonigabriel/coder-core:latest AS linux-arm64 |
| 7 | +ARG ALT_ARCH=arm64 |
| 8 | + |
| 9 | +# This inherits from the hack above |
| 10 | +FROM ${TARGETOS}-${TARGETARCH} AS builder |
| 11 | +ARG TARGETARCH |
| 12 | +ARG CLOUDFLARE_VERSION=2022.9.0 |
| 13 | +ARG OPENVSCODE_VERSION=v1.71.0 |
| 14 | + |
| 15 | +# Install npm, nodejs and some tools required to build native node modules |
| 16 | +RUN sudo apk --no-cache add npm build-base libsecret-dev python3 wget |
| 17 | + |
| 18 | +# Setup a dummy project |
| 19 | +RUN cd /tmp && \ |
| 20 | + npm init -y && \ |
| 21 | +# Then add dependencies |
| 22 | + npm install keytar node-pty spdlog native-watchdog @parcel/watcher && \ |
| 23 | +# Remove any precompiled native modules |
| 24 | + find /tmp/node_modules -name "*.node" -exec rm -rf {} \; |
| 25 | + |
| 26 | +# Build keytar native modue |
| 27 | +RUN cd /tmp/node_modules/keytar && \ |
| 28 | + npm run build && \ |
| 29 | + strip /tmp/node_modules/keytar/build/Release/keytar.node |
| 30 | + |
| 31 | +# Build node-pty native modue |
| 32 | +RUN cd /tmp/node_modules/node-pty && \ |
| 33 | + npm install && \ |
| 34 | + strip /tmp/node_modules/node-pty/build/Release/pty.node |
| 35 | + |
| 36 | +# Build spdlog native modue |
| 37 | +RUN cd /tmp/node_modules/spdlog && \ |
| 38 | + npm rebuild && \ |
| 39 | + strip /tmp/node_modules/spdlog/build/Release/spdlog.node |
| 40 | + |
| 41 | +# Build native-watchdog native modue |
| 42 | +RUN cd /tmp/node_modules/native-watchdog && \ |
| 43 | + npm rebuild && \ |
| 44 | + strip /tmp/node_modules/native-watchdog/build/Release/watchdog.node |
| 45 | + |
| 46 | +# Build @parcel/watcher native modue |
| 47 | +RUN cd /tmp/node_modules/@parcel/watcher && \ |
| 48 | + npm install && \ |
| 49 | + strip /tmp/node_modules/@parcel/watcher/build/Release/watcher.node |
| 50 | + |
| 51 | +# Download 'cloudflared' manually instead of using apk. |
| 52 | +# This is currently required because it is only available on the edge/testing Alpine repo. |
| 53 | +RUN wget https://github.com/cloudflare/cloudflared/releases/download/${CLOUDFLARE_VERSION}/cloudflared-linux-${TARGETARCH} && \ |
| 54 | + chmod +x cloudflared-linux-${TARGETARCH} && \ |
| 55 | +# Remove debug symbols |
| 56 | + strip cloudflared-linux-${TARGETARCH} && \ |
| 57 | +# Put it into a 'staging' folder |
| 58 | + mkdir -p /tmp/staging/usr/bin && \ |
| 59 | + mv cloudflared-linux-${TARGETARCH} /tmp/staging/usr/bin/cloudflared && \ |
| 60 | + sudo chown root:root /tmp/staging/usr/bin/cloudflared |
| 61 | + |
| 62 | +# Download 'openvscode-server' |
| 63 | +RUN wget https://github.com/gitpod-io/openvscode-server/releases/download/openvscode-server-v1.71.0/openvscode-server-${OPENVSCODE_VERSION}-linux-${ALT_ARCH}.tar.gz && \ |
| 64 | +# Unpack it |
| 65 | + tar -xf openvscode-server-${OPENVSCODE_VERSION}-linux-${ALT_ARCH}.tar.gz && \ |
| 66 | + rm openvscode-server-${OPENVSCODE_VERSION}-linux-${ALT_ARCH}.tar.gz && \ |
| 67 | +# Remove the 'node binary that comes with it |
| 68 | + rm openvscode-server-${OPENVSCODE_VERSION}-linux-${ALT_ARCH}/node && \ |
| 69 | +# Replacing it with a symlink |
| 70 | + ln -s /usr/bin/node ./openvscode-server-v1.71.0-linux-${ALT_ARCH}/node && \ |
| 71 | +# Remove pre-compiled binary node modules |
| 72 | + find . -name "*.node" -exec rm -rf {} \; && \ |
| 73 | +# Put everything into a 'staging' folder |
| 74 | + sudo mkdir -p /tmp/staging/opt/ && \ |
| 75 | + sudo mv openvscode-server-${OPENVSCODE_VERSION}-linux-${ALT_ARCH} /tmp/staging/opt/openvscode-server && \ |
| 76 | + sudo cp /tmp/node_modules/keytar/build/Release/keytar.node /tmp/staging/opt/openvscode-server/node_modules/keytar/build/Release/keytar.node && \ |
| 77 | + sudo cp /tmp/node_modules/node-pty/build/Release/pty.node /tmp/staging/opt/openvscode-server/node_modules/node-pty/build/Release/pty.node && \ |
| 78 | + sudo cp /tmp/node_modules/spdlog/build/Release/spdlog.node /tmp/staging/opt/openvscode-server/node_modules/spdlog/build/Release/spdlog.node && \ |
| 79 | + sudo cp /tmp/node_modules/native-watchdog/build/Release/watchdog.node /tmp/staging/opt/openvscode-server/node_modules/native-watchdog/build/Release/watchdog.node && \ |
| 80 | + sudo cp /tmp/node_modules/@parcel/watcher/build/Release/watcher.node /tmp/staging/opt/openvscode-server/node_modules/@parcel/watcher/build/Release/watcher.node && \ |
| 81 | + sudo chown -R root:root /tmp/staging/opt/openvscode-server |
| 82 | + |
| 83 | +# This inherits from the hack above |
| 84 | +FROM ${TARGETOS}-${TARGETARCH} AS final |
| 85 | +ARG TARGETARCH |
| 86 | + |
| 87 | +# Copy stuff from the staging folder of the 'builder' stage |
| 88 | +COPY --from=builder /tmp/staging / |
| 89 | + |
| 90 | +ENV PATH=$PATH:/opt/openvscode-server/bin |
| 91 | +EXPOSE 8000 |
| 92 | +CMD ["openvscode-server", "serve-local", "--host", "0.0.0.0", "--port", "8000", "--accept-server-license-terms", "--disable-telemetry", "--without-connection-token"] |
0 commit comments