Skip to content

Commit

Permalink
Add DOJ demo (#61)
Browse files Browse the repository at this point in the history
* Remove unused pdf->html processing

* Add initial demo site for the DOJ Office of the Pardon Attorney.

* Tweak Astro to host static files correctly.

* Add infra config for a cloud.gov space, initially populated with a placeholder for the DOJ demo Astro site.

* Docker config for Astro web server with cloud.gov/tfcdk config

* Add workflow_dispatch to deploy workflow

* Do a "cdktf get" on "postinstall"

* Revert "Do a "cdktf get" on "postinstall""

This reverts commit 0c68ba4.

* Exclude "infra" package from root build, so we don't break cloud.gov pages due to a missing terraform binary

* Don't run infra tests, by default.
  • Loading branch information
danielnaab authored Mar 11, 2024
1 parent cd9f5e8 commit 918978a
Show file tree
Hide file tree
Showing 50 changed files with 1,714 additions and 2,676 deletions.
15 changes: 15 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
node_modules
#.git
.env
.gitignore

.DS_Store
.env
*.code-workspace
_site
.turbo/
.vscode/
coverage/
html/
NOTES.md
tsconfig.tsbuildinfo
75 changes: 75 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: 'Run tests'

on:
push:
branches:
- main
workflow_dispatch:

env:
TAG_NAME: ghcr.io/gsa-tts/tts-10x-atj-dev/doj-demo:latest

jobs:
init-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Read node version from `.nvmrc` file
id: nvmrc
shell: bash
run: echo ::set-output name=NODE_VERSION::$(cat .nvmrc)

- name: Install required node.js version
uses: actions/setup-node@v3
with:
node-version: ${{ steps.nvmrc.outputs.NODE_VERSION }}

- name: Install pnpm
uses: pnpm/action-setup@v2
id: pnpm-install
with:
version: 8
run_install: false
- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install

build-image:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Build container image
run: docker build . --platform linux/amd64 --target doj-demo --tag ${TAG_NAME}

- name: Publish to container registry
run: docker push ${TAG_NAME}

deploy:
runs-on: ubuntu-latest
needs: [build-image, init-deploy]
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Initialize Terraform CDK configuration
run: pnpm build

- name: Apply Terraform CDK configuration
run: pnpm cdktf deploy
33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM node:20-bookworm AS base

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable

FROM base AS build

RUN apt update && \
apt install -y git
COPY . /usr/src/app
WORKDIR /usr/src/app
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
RUN pnpm build
RUN pnpm deploy --filter=doj-demo --prod /app/doj-demo
#RUN pnpm deploy --filter=spotlight --prod /app/spotlight

FROM base AS doj-demo

LABEL org.opencontainers.image.description 10x-atj DOJ demo

COPY --from=build /app/doj-demo /app/doj-demo
COPY --from=build /usr/src/app/apps/doj-demo/dist /app/doj-demo/dist
WORKDIR /app/doj-demo

ENV HOST=0.0.0.0
ENV PORT=4321
EXPOSE 4321

CMD [ "node", "./dist/server/entry.mjs" ]

#HEALTHCHECK --interval=5m --timeout=3s \
# CMD curl -f http://localhost:4321/ || exit 1
21 changes: 21 additions & 0 deletions apps/doj-demo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# build output
dist/
# generated types
.astro/

# dependencies
node_modules/

# logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*


# environment variables
.env
.env.production

# macOS-specific files
.DS_Store
1 change: 1 addition & 0 deletions apps/doj-demo/.nvmrc
47 changes: 47 additions & 0 deletions apps/doj-demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Astro Starter Kit: Minimal

```sh
npm create astro@latest -- --template minimal
```

[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/withastro/astro/tree/latest/examples/minimal)
[![Open with CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/p/sandbox/github/withastro/astro/tree/latest/examples/minimal)
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/withastro/astro?devcontainer_path=.devcontainer/minimal/devcontainer.json)

> 🧑‍🚀 **Seasoned astronaut?** Delete this file. Have fun!
## 🚀 Project Structure

Inside of your Astro project, you'll see the following folders and files:

```text
/
├── public/
├── src/
│ └── pages/
│ └── index.astro
└── package.json
```

Astro looks for `.astro` or `.md` files in the `src/pages/` directory. Each page is exposed as a route based on its file name.

There's nothing special about `src/components/`, but that's where we like to put any Astro/React/Vue/Svelte/Preact components.

Any static assets, like images, can be placed in the `public/` directory.

## 🧞 Commands

All commands are run from the root of the project, from a terminal:

| Command | Action |
| :------------------------ | :----------------------------------------------- |
| `npm install` | Installs dependencies |
| `npm run dev` | Starts local dev server at `localhost:4321` |
| `npm run build` | Build your production site to `./dist/` |
| `npm run preview` | Preview your build locally, before deploying |
| `npm run astro ...` | Run CLI commands like `astro add`, `astro check` |
| `npm run astro -- --help` | Get help using the Astro CLI |

## 👀 Want to learn more?

Feel free to check [our documentation](https://docs.astro.build) or jump into our [Discord server](https://astro.build/chat).
29 changes: 29 additions & 0 deletions apps/doj-demo/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { defineConfig } from 'astro/config';
import node from '@astrojs/node';
import react from '@astrojs/react';

// https://astro.build/config
export default defineConfig({
output: 'server',
trailingSlash: 'never',
base: addTrailingSlash(process.env.BASEURL || ''),
adapter: node({
mode: 'standalone',
}),
integrations: [
react({
include: ['src/components/react/**'],
}),
],
server: {
port: 80,
},
});

function addTrailingSlash(path) {
var lastChar = path.substr(-1);
if (lastChar === '/') {
return path;
}
return path + '/';
}
29 changes: 29 additions & 0 deletions apps/doj-demo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "doj-demo",
"type": "module",
"version": "0.0.1",
"scripts": {
"dev": "astro dev",
"start": "astro dev",
"build": "astro check && astro build",
"preview": "astro preview",
"astro": "astro"
},
"dependencies": {
"@astrojs/check": "^0.5.6",
"@astrojs/node": "^8.2.3",
"@astrojs/react": "^3.0.9",
"@atj/design": "workspace:*",
"@atj/documents": "workspace:*",
"@atj/form-service": "workspace:*",
"@atj/forms": "workspace:*",
"astro": "^4.4.11",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-error-boundary": "^4.0.12",
"typescript": "^5.3.3"
},
"devDependencies": {
"@types/react": "^18.2.62"
}
}
Binary file added apps/doj-demo/public/favicon.ico
Binary file not shown.
1 change: 1 addition & 0 deletions apps/doj-demo/public/uswds
26 changes: 26 additions & 0 deletions apps/doj-demo/src/components/AppAvailableFormList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';
import { ErrorBoundary } from 'react-error-boundary';

import { AvailableFormList } from '@atj/design';
import { getAppContext } from '../context';
import { getFormUrl } from '../routes';
import DebugTools from './DebugTools';

export default () => {
const ctx = getAppContext();
return (
<ErrorBoundary
fallback={
<div>
There was an unexpected error rendering the form list.
<DebugTools />
</div>
}
>
<AvailableFormList
formService={ctx.formService}
urlForForm={getFormUrl}
/>
</ErrorBoundary>
);
};
25 changes: 25 additions & 0 deletions apps/doj-demo/src/components/AppFormManager.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';

import {
FormManager,
defaultFormElementComponents,
defaultFormElementEditComponents,
} from '@atj/design';

import { getAppContext } from '../context';

export default function () {
const ctx = getAppContext();
return (
<FormManager
context={{
config: ctx.formConfig,
components: defaultFormElementComponents,
editComponents: defaultFormElementEditComponents,
uswdsRoot: ctx.uswdsRoot,
}}
formService={ctx.formService}
baseUrl={ctx.baseUrl}
/>
);
}
18 changes: 18 additions & 0 deletions apps/doj-demo/src/components/AppFormRouter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';

import { FormRouter, defaultFormElementComponents } from '@atj/design';
import { getAppContext } from '../context';

export default function AppFormRouter() {
const ctx = getAppContext();
return (
<FormRouter
context={{
config: ctx.formConfig,
components: defaultFormElementComponents,
uswdsRoot: ctx.uswdsRoot,
}}
formService={ctx.formService}
/>
);
}
18 changes: 18 additions & 0 deletions apps/doj-demo/src/components/DebugTools.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';

export default function DebugTools() {
return (
<section>
<button
className="usa-button"
onClick={() => {
console.warn('clearing localStorage...');
window.localStorage.clear();
window.location.reload();
}}
>
Delete all demo data (clear browser local storage)
</button>
</section>
);
}
26 changes: 26 additions & 0 deletions apps/doj-demo/src/components/Footer.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
---

<footer class="usa-footer usa-footer--slim">
<div class="grid-container usa-footer__return-to-top">
<a href="#">Return to top</a>
</div>
<div class="usa-footer__primary-section">
<div class="usa-footer__primary-container grid-row">
<div class="mobile-lg:grid-col-8">
<nav class="usa-footer__nav" aria-label="Footer navigation,">
<ul class="grid-row grid-gap">
<li
class="mobile-lg:grid-col-6 desktop:grid-col-auto usa-footer__primary-content"
>
<a class="usa-footer__primary-link" href="https://10x.gsa.gov/">
10x
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
</footer>
Loading

0 comments on commit 918978a

Please sign in to comment.