From 0e111e22ec44ba18ddd2fb94bf117317105e218c Mon Sep 17 00:00:00 2001 From: "Kyle J. Burda" <47502769+kylejb@users.noreply.github.com> Date: Fri, 27 Dec 2024 15:39:23 -0500 Subject: [PATCH] build: add `Dockerfile` (#25) * chore: add Dockerfile * chore(web): remove pre-commit configuration and Dockerfile * chore(docs): remove CHANGELOG * chore(web): replace scripts with task commands * fix(web): extend vite config with vitetest config for type safety --- .taskfiles/web.taskfile.yml | 7 +++++++ CHANGELOG.md | 1 - Dockerfile | 38 +++++++++++++++++++++++++++++++++++++ pkg/noaa/README.md | 3 ++- web/.pre-commit-config.yaml | 27 -------------------------- web/Dockerfile | 13 ------------- web/package.json | 8 +------- web/scripts/README.md | 29 ---------------------------- web/scripts/bootstrap | 32 ------------------------------- web/scripts/clean | 11 ----------- web/scripts/init | 9 --------- web/scripts/run | 26 ------------------------- web/scripts/setup | 9 --------- web/scripts/start | 5 ----- web/scripts/uninstall | 12 ------------ web/vite.config.ts | 4 +--- 16 files changed, 49 insertions(+), 185 deletions(-) delete mode 100644 CHANGELOG.md create mode 100644 Dockerfile delete mode 100644 web/.pre-commit-config.yaml delete mode 100644 web/Dockerfile delete mode 100644 web/scripts/README.md delete mode 100755 web/scripts/bootstrap delete mode 100755 web/scripts/clean delete mode 100755 web/scripts/init delete mode 100755 web/scripts/run delete mode 100755 web/scripts/setup delete mode 100755 web/scripts/start delete mode 100755 web/scripts/uninstall diff --git a/.taskfiles/web.taskfile.yml b/.taskfiles/web.taskfile.yml index 247f08a..8c2d0f5 100644 --- a/.taskfiles/web.taskfile.yml +++ b/.taskfiles/web.taskfile.yml @@ -12,6 +12,13 @@ tasks: cmds: - npm run build + clean: + silent: true + desc: Clean dist directory + cmds: + - | + [ -d 'dist' ] && rm -rf dist || true + deps: desc: Install all dependencies cmds: diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 420e6f2..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1 +0,0 @@ -# Change Log diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5ce3d39 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +# TODO(@kylejb): revisit directory structure to simplify embedding of web and set non-root user for security +FROM node:lts-alpine AS web_builder + +RUN npm i -g @go-task/cli + +WORKDIR /app + +COPY .taskfiles .taskfiles/ +COPY Taskfile.yml ./ +COPY web web/ + +RUN task web:deps +RUN task web:build + + +FROM golang:1-alpine AS api_builder + +RUN go install github.com/go-task/task/v3/cmd/task@latest + +WORKDIR /app + +COPY . . +COPY --from=web_builder /app/web/dist /app/web/dist/ + +RUN task api:build + + +FROM alpine AS production + +RUN apk upgrade --no-cache + +WORKDIR / + +COPY --from=api_builder /app/api /app/swellhub + +EXPOSE 4000 + +CMD ["/app/swellhub"] diff --git a/pkg/noaa/README.md b/pkg/noaa/README.md index df6de91..22baee8 100644 --- a/pkg/noaa/README.md +++ b/pkg/noaa/README.md @@ -1,3 +1,4 @@ # noaa -`noaa` is a Go package that was built to facilitate rapid discovery of new data from [NOAA](https://www.noaa.gov) and [NDBC](https://www.ndbc.noaa.gov). +`noaa` is a Go package that was built to facilitate rapid discovery of new data +from [NOAA](https://www.noaa.gov) and [NDBC](https://www.ndbc.noaa.gov). diff --git a/web/.pre-commit-config.yaml b/web/.pre-commit-config.yaml deleted file mode 100644 index 6a873e4..0000000 --- a/web/.pre-commit-config.yaml +++ /dev/null @@ -1,27 +0,0 @@ -repos: - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v5.0.0 - hooks: - - id: check-added-large-files - - id: check-merge-conflict - - id: end-of-file-fixer - - id: trailing-whitespace - - repo: https://github.com/lovesegfault/beautysh - rev: v6.2.1 - hooks: - - id: beautysh - - repo: https://github.com/pre-commit/mirrors-eslint - rev: v9.15.0 - hooks: - - id: eslint - files: \.[jt]sx?$ - types: [file] - - repo: https://github.com/clairBuoyant/pre-commit - rev: v0.2.0 - hooks: - - id: branch-validate - - repo: https://github.com/commitizen-tools/commitizen - rev: v3.31.0 - hooks: - - id: commitizen - stages: [commit-msg] diff --git a/web/Dockerfile b/web/Dockerfile deleted file mode 100644 index fd72bb1..0000000 --- a/web/Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -FROM node:21-slim - -WORKDIR /app -ADD . /app - -ENV NODE_PATH=/web/node_modules -ENV PATH=$PATH:/web/node_modules/.bin - -EXPOSE 8000 -EXPOSE 35729 - -ENTRYPOINT ["/bin/bash", "/app/scripts/run"] -CMD ["start"] diff --git a/web/package.json b/web/package.json index fa8c7a4..b29e1fa 100644 --- a/web/package.json +++ b/web/package.json @@ -62,17 +62,11 @@ "vitest": "^2.1.8" }, "scripts": { - "bootstrap": "./scripts/bootstrap", "build": "vite build", - "clean": "./scripts/clean", "dev": "vite", - "init": "./scripts/init", "lint": "eslint src", "preview": "vite preview", - "setup": "./scripts/setup", - "start": "./scripts/start", - "test": "vitest", - "uninstall": "./scripts/uninstall" + "test": "vitest" }, "browserslist": { "production": [ diff --git a/web/scripts/README.md b/web/scripts/README.md deleted file mode 100644 index f1b750f..0000000 --- a/web/scripts/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# Development Scripts - -These scripts are provided for development of [clairBuoyant](https://www.github.com/clairBuoyant). The script names are standardized across all repositories for clairBuoyant to simplify the development experience. - -### Available Commands - -- `bootstrap`: resolve all system dependencies the application needs to run. -- `clean`: remove all unnecessary build artifacts. -- `init`: run bootstrap and setup. -- `setup`: install node dependencies and githooks. -- `start`: start app locally. -- `uninstall`: remove node dependencies and build artifacts. - -### Usage - -These scripts can be used directly or with `npm` (**recommended**). - -1. Run with npm: `npm run ` (e.g., `npm run init`). -2. Run script directly: - - `./scripts/` (e.g., `./scripts/init`). - - Run `. ./aliases` in your terminal in order to run any script just by `` (e.g., `init` or `start`). 1 - -#### Note - -1. This script needs to be re-run every time you start a new terminal session. But, it saves you from prepending `npm run` every time! :) - -### Attribution - -Styled after GitHub's ["Scripts to Rule Them All"](https://github.com/github/scripts-to-rule-them-all). diff --git a/web/scripts/bootstrap b/web/scripts/bootstrap deleted file mode 100755 index a842a91..0000000 --- a/web/scripts/bootstrap +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash -e -# -# Resolve all system dependencies the application needs to run. - -PYV=$(python3 -c 'import sys; sys.stdout.write("true") if sys.version_info.major >= 3 and sys.version_info.minor >= 11 else sys.stdout.write("false");') -if ! $PYV -then - echo 'Python version 3.11 or greater is required.' - exit 1 -fi - -JSV=$(node -e 'const [major, minor] = process.version.slice(1).split(".").map(n => Number(n)); major >= 19 && minor >= 7 ? console.log("true") : console.log("false");') -if ! $JSV -then - echo 'Node version 19.7 or greater is required.' - exit 1 -fi - -echo 'Checking for pre-commit...' -if ! command -v pre-commit &> /dev/null -then - echo 'pre-commit not found. Installing with pipx...' - if ! command -v pipx &> /dev/null - then - echo 'pipx was not found. Installing pipx first...' - python3 -m pip install --user pipx - python3 -m pipx ensurepath - fi - pipx install pre-commit -fi - -echo 'System dependencies installed.' diff --git a/web/scripts/clean b/web/scripts/clean deleted file mode 100755 index b1d8155..0000000 --- a/web/scripts/clean +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -ex -# -# Remove all build artifacts. - -if [ -d 'build' ] ; then - rm -r build -fi - -if [ -d 'dist' ] ; then - rm -r dist -fi diff --git a/web/scripts/init b/web/scripts/init deleted file mode 100755 index 2b6d80e..0000000 --- a/web/scripts/init +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -e -# -# Prepare application for development by running bootstrap and setup. - -CURRENT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) -BASE_DIR="$(dirname "$CURRENT_DIR")" - -"${BASE_DIR}"/scripts/bootstrap -"${BASE_DIR}"/scripts/setup diff --git a/web/scripts/run b/web/scripts/run deleted file mode 100755 index 83b1ab8..0000000 --- a/web/scripts/run +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash -# -# Docker entrypoint. - -set -e - -case $1 in - build) - npm build - ;; - dev) - npm run dev - ;; - preview) - npm run preview - ;; - start) - npm start - ;; - test) - npm test "$@" - ;; - *) - npm run "$@" - ;; -esac diff --git a/web/scripts/setup b/web/scripts/setup deleted file mode 100755 index 876c261..0000000 --- a/web/scripts/setup +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -e -# -# Install node dependencies and githooks. - -command -v pre-commit &> /dev/null && pre-commit install --hook-type commit-msg || echo >&2 'pre-commit not found.' - -npm ci - -# npx update-browserslist-db@latest diff --git a/web/scripts/start b/web/scripts/start deleted file mode 100755 index 6d21c35..0000000 --- a/web/scripts/start +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -e -# -# Start application locally. - -npm run dev diff --git a/web/scripts/uninstall b/web/scripts/uninstall deleted file mode 100755 index e830892..0000000 --- a/web/scripts/uninstall +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -ex -# -# Remove node dependencies and build artifacts. - -CURRENT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) -BASE_DIR="$(dirname "$CURRENT_DIR")" - -"${BASE_DIR}"/scripts/clean - -if [ -d 'node_modules' ] ; then - rm -r node_modules -fi diff --git a/web/vite.config.ts b/web/vite.config.ts index 7a51e8d..1912e45 100644 --- a/web/vite.config.ts +++ b/web/vite.config.ts @@ -1,9 +1,7 @@ -/// - import react from '@vitejs/plugin-react-swc'; import { resolve } from 'path'; -import { defineConfig } from 'vite'; import eslintPlugin from 'vite-plugin-eslint'; +import { defineConfig } from 'vitest/config'; export default defineConfig({ resolve: {