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 1b92a02 commit a141604
Show file tree
Hide file tree
Showing 11 changed files with 359 additions and 120 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: e2e
name: End-to-end tests

on:
pull_request:

Expand Down
58 changes: 58 additions & 0 deletions .github/workflows/images.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Publish images

on:
push:
tags:
- 'v*'

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
image:
- compile
- data-dev

env:
REGISTRY: ghcr.io
IMAGE_NAME: pi-base/${{ matrix.image }}

permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- 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 }}/pi-base/${{ matrix.image }}
tags: |
type=semver,pattern={{version}}
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 }}
3 changes: 2 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: test
name: Unit tests

on:
push:

Expand Down
27 changes: 27 additions & 0 deletions images/compile/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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 && \
pnpm run --filter core build && \
pnpm run --filter compile build && \
pnpm deploy --filter compile --prod /prod/compile

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

ENTRYPOINT ["node", "/app/dist/esm/main.js"]
11 changes: 0 additions & 11 deletions packages/compile/action.yml

This file was deleted.

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
26 changes: 13 additions & 13 deletions packages/compile/src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ import { join } from 'node:path'

const main = join(__dirname, '..', 'src', 'main.ts')
const repo = join(__dirname, '..', 'test', 'repo')
const out = join(repo, 'out.json')
const out = 'out.json'

async function run(dir: string) {
const { stdout, stderr, error, status } = spawnSync('tsx', [main], {
env: {
GITHUB_REF: 'refs/heads/test',
GITHUB_SHA: 'c74d99cf46f6ed23e742f2617e9908294b4a608b',
GITHUB_WORKSPACE: join(repo, dir),
INPUT_OUT: out,
PATH: process.env.PATH,
const { stdout, stderr, error, status } = spawnSync(
'tsx',
[main, join(repo, dir), out],
{
env: {
GITHUB_REF: 'refs/heads/test',
GITHUB_SHA: 'c74d99cf46f6ed23e742f2617e9908294b4a608b',
PATH: process.env.PATH,
},
},
})
)

if (error) {
throw error
Expand All @@ -43,12 +45,10 @@ afterAll(cleanup)

it('builds a bundle', async () => {
const { output, error } = await run('valid')
expect(output).toContain(
`::debug::Compiling repo=${repo}/valid to out=${out}`,
)
expect(output).toContain(`::debug Compiling repo=${repo}/valid to out=`)
expect(error).toBe(false)

const bundle = JSON.parse((await readFile(out)).toString())
const bundle = JSON.parse((await readFile(`${repo}/valid/${out}`)).toString())

expect(bundle.properties.length).toEqual(3)
expect(bundle.spaces.length).toEqual(2)
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 = '.', 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))
1 change: 1 addition & 0 deletions packages/compile/test/repo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.json
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"dependencies": {
"debug": "^4.3.4",
"micromark-util-types": "^1.0.2",
"micromark-util-types": "1.0.2",
"rehype-katex": "^6.0.3",
"rehype-stringify": "^9.0.3",
"remark": "^14.0.2",
Expand Down
Loading

0 comments on commit a141604

Please sign in to comment.