From 386c3c1e62c582263f857112d329bc2da81d6b60 Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Tue, 1 Jul 2025 12:36:37 -0700 Subject: [PATCH] Add Docker web port image --- .github/workflows/docker.yml | 52 +++++++++++++++++++++++++++++++++ docker/emscripten/Dockerfile | 40 +++++++++++++++++++++++++ docker/emscripten/entrypoint.sh | 6 ++++ docker/emscripten/nginx.conf | 33 +++++++++++++++++++++ 4 files changed, 131 insertions(+) create mode 100644 .github/workflows/docker.yml create mode 100644 docker/emscripten/Dockerfile create mode 100755 docker/emscripten/entrypoint.sh create mode 100644 docker/emscripten/nginx.conf diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 00000000..fdd31afa --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,52 @@ +name: Publish web port Docker image + +on: + push: + branches: ['master'] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + attestations: write + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + id: push + uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + with: + file: docker/emscripten/Dockerfile + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + - name: Generate artifact attestation + uses: actions/attest-build-provenance@v2 + with: + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} + subject-digest: ${{ steps.push.outputs.digest }} + push-to-registry: true diff --git a/docker/emscripten/Dockerfile b/docker/emscripten/Dockerfile new file mode 100644 index 00000000..60ba1855 --- /dev/null +++ b/docker/emscripten/Dockerfile @@ -0,0 +1,40 @@ +FROM emscripten/emsdk:latest + +ARG USE_ISLE_PIZZA=false +ARG CMAKE_VERSION=3.29.3 + +WORKDIR /src +USER root + +RUN apt-get update && apt-get install -y git wget nginx && rm -rf /var/lib/apt/lists/* +RUN wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-Linux-x86_64.sh -O /tmp/cmake.sh && \ + chmod +x /tmp/cmake.sh && \ + /tmp/cmake.sh --skip-license --prefix=/usr/local && \ + rm /tmp/cmake.sh + +COPY docker/emscripten/nginx.conf /etc/nginx/nginx.conf +COPY docker/emscripten/entrypoint.sh /usr/local/bin/entrypoint.sh + +RUN chmod +x /usr/local/bin/entrypoint.sh +RUN chown -R emscripten:emscripten /src + +USER emscripten + +COPY ISLE/emscripten/libwasmfs_fetch.js.patch /tmp/ +RUN cd /emsdk/upstream/emscripten && \ + git apply --check /tmp/libwasmfs_fetch.js.patch && \ + git apply /tmp/libwasmfs_fetch.js.patch + +COPY --chown=emscripten:emscripten . . + +RUN emcmake cmake -S . -B build -DISLE_BUILD_CONFIG=OFF -DISLE_DEBUG=OFF -DCMAKE_BUILD_TYPE=Release -DISLE_EMSCRIPTEN_HOST=/assets && \ + emmake cmake --build build -j 32 + +RUN echo "Fetching isle.pizza frontend..."; \ + git clone --depth 1 https://github.com/isledecomp/isle.pizza /tmp/isle.pizza && \ + cp -r /tmp/isle.pizza/* /src/build/ && \ + rm -rf /tmp/isle.pizza; + +EXPOSE 6931 +USER root +ENTRYPOINT ["entrypoint.sh"] diff --git a/docker/emscripten/entrypoint.sh b/docker/emscripten/entrypoint.sh new file mode 100755 index 00000000..fcacd745 --- /dev/null +++ b/docker/emscripten/entrypoint.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +set -e + +echo "Starting nginx web server on port 6931..." +exec nginx -c /etc/nginx/nginx.conf diff --git a/docker/emscripten/nginx.conf b/docker/emscripten/nginx.conf new file mode 100644 index 00000000..aebe0aaa --- /dev/null +++ b/docker/emscripten/nginx.conf @@ -0,0 +1,33 @@ +daemon off; + +events { + worker_connections 1024; +} + +http { + types { + application/wasm wasm; + } + + include /etc/nginx/mime.types; + + server { + listen 6931; + server_name localhost; + + add_header 'Cross-Origin-Embedder-Policy' 'require-corp'; + add_header 'Cross-Origin-Opener-Policy' 'same-origin'; + add_header 'Cross-Origin-Resource-Policy' 'cross-origin'; + + location / { + root /src/build; + index index.html isle.html; + try_files $uri $uri/ =404; + } + + location /assets/ { + alias /assets/; + autoindex off; + } + } +}