Skip to content

Commit

Permalink
Merge pull request #5 from nationalarchives/proof-of-concept
Browse files Browse the repository at this point in the history
Initial merge
  • Loading branch information
ahosgood authored Jun 21, 2024
2 parents e3bcf53 + 2d6a229 commit bd02c9d
Show file tree
Hide file tree
Showing 147 changed files with 16,678 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .babelrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"sourceType": "unambiguous",
"presets": [
[
"@babel/preset-env",
{
"targets": {
"chrome": 114
}
}
]
],
"plugins": []
}
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.dockerignore
.git
docker-compose.yml
Dockerfile
README.md
node_modules
tmp
.babelrc.json
.eslintrc.js
.flake8
.gitignore
.stylelintrc
3 changes: 3 additions & 0 deletions .environment
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if [ -n "$POETRY_VERSION" ]; then
export PATH="/app/.local/bin:$PATH"
fi
24 changes: 24 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
env: {
browser: true,
es2021: true,
},
extends: ["eslint:recommended"],
overrides: [
{
env: {
node: true,
},
files: [".eslintrc.{js,cjs}"],
parserOptions: {
sourceType: "script",
},
},
],
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
},
rules: {},
ignorePatterns: ["webpack.config.js", "*.min.js", "tmp/*"],
};
6 changes: 6 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[flake8]
ignore = E203, E266, E501, W503, F403, F401
exclude = venv*,__pycache__,node_modules,migrations,tmp
max-line-length = 80
max-complexity = 12
select = B,C,E,F,W,T4,B9
11 changes: 11 additions & 0 deletions .github/actions/node-tests/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Run Node tests

runs:
using: "composite"
steps:
- name: Install Node dependencies
run: npm install
shell: bash
- name: Run Node tests
run: npm run test:all
shell: bash
26 changes: 26 additions & 0 deletions .github/actions/python-tests/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Run Python tests

runs:
using: "composite"
steps:
- uses: actions/setup-python@v5
with:
python-version: 3.12
- uses: snok/install-poetry@v1
with:
version: 1.8.1
virtualenvs-create: true
virtualenvs-in-project: true
virtualenvs-path: .venv
- name: Install Poetry dependencies
run: poetry install --no-interaction --no-root
shell: bash
- name: Make tmp directory
run: mkdir tmp
shell: bash
- name: Clone ds-wagtail
run: cd tmp && git clone https://github.com/nationalarchives/ds-wagtail.git ds-wagtail
shell: bash
- name: Run Python tests
run: poetry run python -m pytest
shell: bash
24 changes: 24 additions & 0 deletions .github/workflows/branch-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Clean up feature branch

on:
delete:

jobs:
delete:
if: github.event.ref_type == 'branch' && startsWith(github.event.ref, 'feature/')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get tag from deleted branch
id: version-tag
run: echo "VERSION=$(echo "${{ github.event.ref }}" | sed -e 's,/,-,g')" >> "$GITHUB_OUTPUT"
- name: Debug
run: echo "Clean up Docker image ${{ vars.DOCKER_IMAGE_NAME }}:${{ steps.version-tag.outputs.VERSION }}"
- name: Delete image
if: ${{ steps.version-tag.outputs.VERSION }}
uses: bots-house/[email protected]
with:
owner: ${{ github.repository_owner }}
name: ${{ vars.DOCKER_IMAGE_NAME }}
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ steps.version-tag.outputs.VERSION }}
78 changes: 78 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Build and deploy

on:
workflow_dispatch:
push:

concurrency:
group: cd-${{ github.ref }}

jobs:
test-node:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run tests
uses: ./.github/actions/node-tests

test-python:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run tests
uses: ./.github/actions/python-tests

version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get tag
id: version-tag
uses: nationalarchives/ds-docker-actions/.github/actions/get-version-tag@main
outputs:
version: ${{ steps.version-tag.outputs.version-tag }}

build:
runs-on: ubuntu-latest
needs:
- test-python
- test-node
- version
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v4
- name: Build Docker image
uses: nationalarchives/ds-docker-actions/.github/actions/docker-build@main
with:
version: ${{ needs.version.outputs.version }}
latest: ${{ github.ref == 'refs/heads/main' }}
github-token: ${{ secrets.GITHUB_TOKEN }}
docker-image-name: ${{ vars.DOCKER_IMAGE_NAME }}

update:
runs-on: ubuntu-latest
needs:
- build
- version
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
with:
repository: nationalarchives/ds-etna-deployments-proof-of-concept
ref: main
token: ${{ secrets.ACTIONS_GITHUB_TOKEN }}
- name: Set up git config
run: |
git config user.name "ds-etna-frontend"
git config user.email "<>"
- name: Install jq
run: sudo apt-get install jq
- name: Update config
run: jq --indent 4 '(.services.frontend.version|="${{ needs.version.outputs.version }}")' config-aws-develop.json > tmp.$$.json && mv tmp.$$.json config-aws-develop.json
- name: Push new version
run: |
git add config-aws-develop.json
git commit -m "Update frontend to v${{ needs.version.outputs.version }}"
git push origin main
22 changes: 22 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Pull request

on:
pull_request:
types:
- opened
- synchronize

jobs:
test-node:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run tests
uses: ./.github/actions/node-tests

test-python:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run tests
uses: ./.github/actions/python-tests
16 changes: 16 additions & 0 deletions .github/workflows/remove-untagged.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Remove untagged container images

on:
workflow_dispatch:
schedule:
- cron: "0 3 * * 1"

jobs:
remove-untagged:
runs-on: ubuntu-latest
steps:
- name: Remove untagged Docker images
uses: nationalarchives/ds-docker-actions/.github/actions/remove-untagged@main
with:
docker-image-name: ${{ vars.DOCKER_IMAGE_NAME }}
github-token: ${{ secrets.GITHUB_TOKEN }}
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.DS_Store
__pycache__
/node_modules
/app/static/assets
/app/static/*.css
/app/static/*.css.map
/app/static/*.min.js
/app/static/*.min.js.map
/tmp
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/iron
58 changes: 58 additions & 0 deletions .platform.app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: app

type: "python:3.11"

variables:
env:
ENVIRONMENT: production
POETRY_VERSION: "1.6.1"
POETRY_VIRTUALENVS_IN_PROJECT: true
POETRY_VIRTUALENVS_CREATE: true
PIP_DISABLE_PIP_VERSION_CHECK: true

disk: 2048

hooks:
build: |
set -eu
python3.11 -m pip install --upgrade pip
export PIP_USER=false
curl -sSL https://install.python-poetry.org | python3 - --version $POETRY_VERSION
export PATH="/app/.local/bin:$PATH"
export PIP_USER=true
poetry install
poetry add [email protected]
npm install
npm run build
mkdir app/static/assets
cp -r node_modules/@nationalarchives/frontend/nationalarchives/assets/* app/static/assets
web:
upstream:
socket_family: unix
commands:
start: "poetry run gunicorn etna:app --bind unix:$SOCKET --capture-output --log-file /var/log/app.log --log-level debug"
locations:
"/":
root: ""
passthru: true
allow: false
"/static":
headers:
Access-Control-Allow-Origin: "*"
root: static
expires: 1y
allow: true

mounts:
tmp:
source: local
source_path: tmp

crons:
renewcert:
spec: "0 4 1,15 * *"
cmd: |
if [ "$PLATFORM_BRANCH" = main ]; then
platform redeploy --yes --no-wait
fi
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/*.html
tmp/**/*
18 changes: 18 additions & 0 deletions .stylelintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["stylelint-config-standard-scss"],
"plugins": ["stylelint-selector-bem-pattern"],
"rules": {
"at-rule-empty-line-before": null,
"block-no-empty": null,
"declaration-empty-line-before": null,
"property-no-vendor-prefix": null,
"value-keyword-case": null,
"scss/dollar-variable-empty-line-before": null,
"scss/double-slash-comment-empty-line-before": null,
"selector-class-pattern": null,
"plugin/selector-bem-pattern": {
"preset": "bem"
}
},
"ignoreFiles": ["app/**/*.css", "tmp/**/*.css", "tmp/**/*.scss"]
}
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
ARG IMAGE=ghcr.io/nationalarchives/tna-python
ARG IMAGE_TAG=latest

FROM "$IMAGE":"$IMAGE_TAG"

ENV NPM_BUILD_COMMAND=compile

# Copy in the application code
COPY --chown=app . .

# Install dependencies
RUN tna-build

# Copy in the static assets from TNA Frontend
RUN mkdir /app/app/static/assets; \
cp -r /app/node_modules/@nationalarchives/frontend/nationalarchives/assets/* /app/app/static/assets

# Delete source files and tests
RUN rm -fR /app/src /app/test

# Run the application
CMD ["tna-run", "etna:app"]
Loading

0 comments on commit bd02c9d

Please sign in to comment.