Skip to content

Commit

Permalink
GitHub Actions CI & esbuild builds
Browse files Browse the repository at this point in the history
Use GitHub actions build and container images. (#4)
Swtich build system from rollup to esbuild. (#3)
  • Loading branch information
ananthb committed Oct 3, 2024
1 parent 3c9c914 commit b8be96d
Show file tree
Hide file tree
Showing 15 changed files with 414 additions and 1,238 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.git
elm-stuff
node_modules
public/index.js
25 changes: 25 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: CI
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
name: CI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '16.9.1'
cache: 'yarn'
- run: yarn install --dev
- run: yarn build
- uses: actions/upload-artifact@v2
with:
name: openapi-explorer
path: public
42 changes: 42 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Create and publish openapi-explorer image

on:
push:
branches: ['main']

env:
REGISTRY: ghcr.io

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Lower-case repository name
run: |
echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}
- name: Checkout repository
uses: actions/checkout@v2

- name: Build image
id: build-image
uses: redhat-actions/buildah-build@v2
with:
image: ${{ env.IMAGE_NAME }}
tags: latest ${{ github.sha }}
dockerfiles: |
./Containerfile
- name: Push to ghcr.io
id: push-to-ghcr
uses: redhat-actions/push-to-registry@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
image: ${{ steps.build-image.outputs.image }}
tags: ${{ steps.build-image.outputs.tags }}
7 changes: 7 additions & 0 deletions Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM docker.io/library/node:16.9.1-alpine AS build
WORKDIR /app
COPY . .
RUN yarn install --dev && yarn build

FROM ghcr.io/ananthb/thttpd-container
COPY --from=build /app/public /srv
20 changes: 0 additions & 20 deletions Jenkinsfile

This file was deleted.

57 changes: 49 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,59 @@ to read. This app will render YAML files in a legible format.
- nodejs runtime
- yarn package manager

Install project dependencies by running `yarn install`.

## Build
Add APIs to the explorer by copying them to the [public](public) folder and
Install dependencies and build the Elm project.


yarn install --dev
yarn build

## Deploy
Add APIs to the explorer by copying them to the public/apis folder and
generating an api index file.
- Each API collection must be in a separate subfolder of the **public/apis** folder.
- The API index file must be at **public/apis/index.json**.
- The API description must be at **public/apis/README.md**.

After the public/apis folder is populated, generate an APIs index using this command (replace \<title> as needed):

pushd public; tree -J -P "*.yaml" apis | jq '{title: "<title>" , contents: .[0].contents}' > apis/index.json; popd

- Copy APIs - `cp -r <api-dir>/ public/`
- Generate API Index - `tree -J -P "*.yaml" public | jq '{title: "<title>" , contents: .[0].contents}' > public/apis.json`
- `yarn build`
**Sample apis folder**

Replace `<api-dir>` and `<title>` in the above commands as needed.
public/apis/
├── content-manager
│ ├── ingest.yaml
│ ├── internal.yaml
│ └── README.md
├── index.json
├── README.md
└── screen-manager
├── automation.yaml
├── iam.yaml
├── media.yaml
├── playback.yaml
├── README.md
├── schedules.yaml
├── shows.yaml
├── storage.yaml
└── system.yaml

[public](public) folder will have a static website that can be deployed to any web server.

[public](public) folder will now have a static website that can be deployed to any web server.
The generated site does not depend on any external resources.

## Containers
openapi-explorer can be built and run in a container.
The /path/to/apis folder must contain valid API definitions along with a generated index.json file as described above.


podman build -t openapi-explorer .
podman run --rm -p 8080:8080 -v /path/to/apis:/srv/apis openapi-explorer

Pre-built containers are available on GitHub Container Registry:

podman pull ghcr.io/RealImage/openapi-explorer

*docker can directly substitute podman in the above commands*

20 changes: 20 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {build, serve} from "esbuild";
import ElmPlugin from "esbuild-plugin-elm";

const productionBuild = process.env.NODE_ENV === "production";
const buildOpts = {
entryPoints: ["index.js"],
bundle: true,
outdir: "public",
plugins: [ElmPlugin({ debug: !productionBuild })],
minify: productionBuild,
}

try {
productionBuild ?
await build(buildOpts) :
await serve({ servedir: "public" }, buildOpts);
} catch (error) {
console.error(error);
process.exit(1);
}
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Elm from "./src/Main.elm";
import { Elm } from "./src/Main.elm";
import "rapidoc";

const serversKey = "servers";
Expand Down
17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
{
"devDependencies": {
"elm-format": "^0.8.3"
"elm-format": "^0.8.3",
"esbuild": "^0.12.28",
"esbuild-plugin-elm": "^0.0.4"
},
"dependencies": {
"@rollup/plugin-node-resolve": "^7.1.3",
"elm": "^0.19.1-3",
"rapidoc": "^8.0.0",
"rollup": "^2.7.6",
"rollup-plugin-elm": "^2.0.2",
"rollup-plugin-terser": "^5.3.0"
"elm": "^0.19.1-5",
"rapidoc": "^9.0.0"
},
"name": "openapi-explorer",
"version": "1.0.0",
"type": "module",
"main": "index.js",
"license": "UNLICENSED",
"private": true,
"scripts": {
"start": "rollup -c --watch",
"build": "rollup -c --environment TERSE"
"watch": "node ./build.js",
"build": "env NODE_ENV=production node ./build.js"
}
}
2 changes: 1 addition & 1 deletion public/bulma.min.css

Large diffs are not rendered by default.

41 changes: 0 additions & 41 deletions rollup.config.js

This file was deleted.

14 changes: 12 additions & 2 deletions src/Api.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ port module Api exposing
, IndexData
, Servers
, apisDecoder
, directory
, dropExtension
, getApis
, getIndex
Expand All @@ -18,6 +19,15 @@ import Json.Decode as Decode exposing (Decoder, field, string)
import RemoteData



{- APIs directory -}


directory : String
directory =
"apis"


dropExtension : String -> String
dropExtension =
splitExtensions >> Tuple.first
Expand Down Expand Up @@ -66,7 +76,7 @@ type alias Data =
getApis : (Data -> msg) -> Cmd msg
getApis got =
Http.get
{ url = "/apis.json"
{ url = directory ++ "/index.json"
, expect =
Http.expectJson
(RemoteData.fromResult >> got)
Expand Down Expand Up @@ -134,7 +144,7 @@ getIndex : String -> (IndexData -> msg) -> Cmd msg
getIndex idx gotIdx =
let
indexFile =
"README.md"
directory ++ "/README.md"
in
Http.get
{ url =
Expand Down
Loading

0 comments on commit b8be96d

Please sign in to comment.