diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..e606d48 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,42 @@ +--- +name: Build & Push Docker + +on: + push: + branches: + - main + +env: + GH_REGISTRY: ghcr.io + +jobs: + build-and-push-github: + runs-on: ubuntu-latest + if: github.repository == 'xtdb/xt-fiddle' + permissions: + contents: read + packages: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ${{ env.GH_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.GH_REGISTRY }}/${{ github.repository }} + tags: | + type=sha,format=short + type=sha,format=long + - name: Build and push Docker image + uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..72ad134 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +FROM clojure:temurin-21-tools-deps-alpine AS frontend-build +WORKDIR /app + +# Install build deps +RUN apk add --update nodejs npm yarn + +# Install node deps +COPY package.json .yarnrc.yml yarn.lock . +RUN yarn install + +# Install clojure build deps +COPY deps.edn . +RUN clojure -P -M:cljs:dev + +# Build the frontend +# TODO: Copy over only cljs files? +COPY . . +RUN npx shadow-cljs release app + + +FROM clojure:temurin-21-tools-deps-alpine +WORKDIR /app + +# Install the runtime deps +COPY deps.edn . +RUN clojure -P + +# Add the source & frontend code +COPY --from=frontend-build /app/resources/public/js/compiled /app/resources/public/js/compiled +# TODO: Copy over only clj files? +COPY . . +CMD clojure -X:prod diff --git a/deps.edn b/deps.edn index 87b0e0c..3669efa 100644 --- a/deps.edn +++ b/deps.edn @@ -50,7 +50,7 @@ "-Dio.netty.tryReflectionSetAccessible=true"]} :prod - {:exec-fn main/-main + {:exec-fn xt-play.main/-main :jvm-opts ["--add-opens=java.base/java.nio=ALL-UNNAMED" "-Dio.netty.tryReflectionSetAccessible=true"]}