From 6fa56cdc6130b349646050b1dad437390fd7ca7a Mon Sep 17 00:00:00 2001 From: Oliver Marshall Date: Thu, 15 Feb 2024 16:11:23 +0000 Subject: [PATCH] feat: build & push docker image --- .dockerignore | 7 +++++++ .github/workflows/build.yml | 40 +++++++++++++++++++++++++++++++++++++ Dockerfile | 32 +++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/workflows/build.yml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0f3513c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +.git +.clj-kondo +.yarn +.shadow-cljs +.lsp +node_modules +resources/public/js/compiled diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..51deb52 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,40 @@ +--- +name: Build & Push Docker + +on: + push: + tags: + - 'v*' + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-docker: + runs-on: ubuntu-latest + if: github.repository == 'xtdb/xt-fiddle' && github.ref == 'refs/heads/main' + 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.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 + 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..a5436dc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +FROM clojure: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 -A:cljs -P + +# Build the frontend +# TODO: Copy over only cljs files? +COPY . . +RUN npx shadow-cljs release app + + +FROM clojure: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