Skip to content

Commit

Permalink
feat: build and publish data-dev container
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesdabbs committed Jan 15, 2024
1 parent 8717bef commit a98971e
Show file tree
Hide file tree
Showing 12 changed files with 404 additions and 864 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.git
*Dockerfile*
node_modules
60 changes: 60 additions & 0 deletions .github/workflows/images.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Publish Docker image

on:
push:
branches:
- jcd/images
- main

env:
REGISTRY: ghcr.io

permissions:
contents: read
packages: write

jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4


build:
needs: setup
runs-on: ubuntu-latest
strategy:
matrix:
image:
- compile
- data-dev
steps:
- name: Lint Dockerfiles
uses: hadolint/[email protected]
with:
dockerfile: images/${{ matrix.image }}/Dockerfile

- 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
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ matrix.image }}
tags: |
type=sha
- name: Build and push
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
file: images/${{ matrix.image }}/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
25 changes: 25 additions & 0 deletions images/compile/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# See https://pnpm.io/docker
FROM node:18-slim AS base

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"

RUN corepack enable

VOLUME /data

COPY . /app
WORKDIR /app

FROM base AS prod-deps
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile

FROM base AS build
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
RUN pnpm run --filter compile build
RUN pnpm deploy --filter compile --prod /prod/compile

FROM base
COPY --from=build /prod/compile /app

ENTRYPOINT ["node", "dist/esm/main.js"]
22 changes: 22 additions & 0 deletions images/data-dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# See https://pnpm.io/docker
FROM node:18-slim AS base

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"

EXPOSE 3141/tcp
EXPOSE 4173/tcp

RUN corepack enable

VOLUME /data

COPY . /app
WORKDIR /app

COPY ./images/data-dev/entrypoint.sh /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh

RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile

ENTRYPOINT ["/bin/bash", "/app/entrypoint.sh"]
3 changes: 3 additions & 0 deletions images/data-dev/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pnpm run --filter compile dev &

VITE_BUNDLE_SSE=true VITE_BUNDLE_HOST=/bundle pnpm run --filter viewer dev --host
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
},
"devDependencies": {
"@types/node": "^18.16.6",
"@vitest/coverage-c8": "^0.29.8",
"@vitest/coverage-v8": "^0.34.0",
"nodemon": "^2.0.22",
"npm-check-updates": "^16.14.6",
"prettier": "^2.8.8",
"prettier-plugin-svelte": "^2.10.0",
"ts-node": "^10.9.1",
"typescript": "^4.9.5",
"vite": "^3.2.6",
"vitest": "^0.31.0"
"typescript": "^5.3.3",
"vite": "^4.5.1",
"vitest": "^0.34.6"
}
}
9 changes: 7 additions & 2 deletions packages/compile/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ author: James Dabbs
inputs:
repo:
description: Path to the cloned repository
default: /data
out:
description: Path to write the bundle to
default: bundle.json
runs:
using: "node12"
main: "dist/main.js"
using: docker
image: docker://ghcr.io/pi-base/compile
args:
- ${{ inputs.repo }}
- ${{ inputs.out }}
1 change: 0 additions & 1 deletion packages/compile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"test:watch": "vitest"
},
"dependencies": {
"@actions/core": "^1.10.0",
"@pi-base/core": "workspace:*",
"chalk": "^5.2.0",
"chokidar": "^3.5.3",
Expand Down
37 changes: 16 additions & 21 deletions packages/compile/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,39 @@
/**
* Entry point for running as a Github action, with the local workspace
* containing the data repository. Set GITHUB_WORKSPACE to use a different
* data repository.
*/
import * as core from '@actions/core'
import * as fs from 'fs'
import * as process from 'process'
import { bundle as B } from '@pi-base/core'

import load from './load.js'

async function run(): Promise<void> {
const repo: string = process.env.GITHUB_WORKSPACE || '.'
const outpath: string = core.getInput('out')

core.debug(`Compiling repo=${repo} to out=${outpath}`)
async function run(repo = '/data', out = 'bundle.json'): Promise<void> {
log(`Compiling repo=${repo} to out=${out}`, 'debug')

const { bundle, errors } = await load(repo)

if (errors) {
errors.forEach((messages, path) => {
messages.forEach(message => {
error(path, message)
log(`file=${path}::${message}`, 'error')
})
})
}

if (errors || !bundle) {
core.setFailed('Compilation finished with errors')
return
log('Compilation finished with errors', 'error')
process.exit(1)
}

fs.writeFileSync(outpath, JSON.stringify(B.serialize(bundle)))
fs.writeFileSync(`${repo}/${out}`, JSON.stringify(B.serialize(bundle)))
}

type Level = 'debug' | 'info' | 'error'

function log(message: string, level: Level = 'info') {
console.log(`::${level} ${message}`)
}

function error(file: string, message: string) {
console.log(`::error file=${file}::${message}`)
function fail(message: string) {
log(message, 'error')
process.exit(1)
}

run().catch(err => {
core.setFailed(err.message)
core.error(err.message)
})
run(...process.argv.slice(2)).catch(err => fail(err.message))
4 changes: 2 additions & 2 deletions packages/core/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export default defineConfig({
test: {
coverage: {
lines: 93.04,
branches: 94.35,
branches: 93.52,
statements: 93.04,
functions: 84.21,
functions: 93.54,
skipFull: true,
thresholdAutoUpdate: true,
exclude: ['src/Formula/Grammar.ts', 'test'],
Expand Down
8 changes: 4 additions & 4 deletions packages/viewer/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export default defineConfig({
test: {
include: ['src/**/*.{test,spec}.{js,ts}'],
coverage: {
lines: 82.91,
branches: 87.36,
statements: 82.91,
functions: 80.19,
lines: 82.99,
branches: 85.71,
statements: 82.99,
functions: 81.33,
skipFull: true,
thresholdAutoUpdate: true,
},
Expand Down
Loading

0 comments on commit a98971e

Please sign in to comment.