Skip to content

Commit

Permalink
chore: clean up the codebase
Browse files Browse the repository at this point in the history
Removing most of the stuff added by default by the practical.li
templates (while being very grateful to their authors for enabling me to
get started). Also re-architecturing the directory structure, and
changing the way we start the shadow-cljs build.
  • Loading branch information
goshatch committed Jan 30, 2025
1 parent 276bfc3 commit 3bfeb5e
Show file tree
Hide file tree
Showing 52 changed files with 201 additions and 537 deletions.
4 changes: 2 additions & 2 deletions .dir-locals.el
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
((clojure-mode . ((cider-preferred-build-tool . clojure-cli)
(cider-default-cljs-repl . shadow)
(cider-shadow-default-options . "app")
(cider-shadow-default-options . "frontend")
(cider-offer-to-open-cljs-app-in-browser . nil)
(cider-clojure-cli-aliases . ":test/env:dev/reloaded"))))
(cider-clojure-cli-aliases . ":test/env"))))
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@
!test/
!test-data/
!resources/
!public/
31 changes: 8 additions & 23 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,35 +1,26 @@
# ------------------------
# Clojure Project Git Ignore file patterns
#
# Ignore all except patterns starting with !
# Add comments on separate lines, not same line as pattern
# ------------------------

# ------------------------
# Ignore everthing in root directory
/*

# ------------------------
# Common project files
!CHANGELOG.md
!README.md
!LICENSE

# ------------------------
# Include Clojure project & config
!build.clj
!deps.edn
!pom.xml
!dev/
!docs/
!src/
!test/
!config.edn

# Don't ignore resources
!resources/
# ...but ignore shadow-cljs build artifacts
resources/public/js

# ------------------------
# Public directory rules
!public/
# Handle js subdirectory specifically
!public/js/
public/js/*
!public/js/.keep

# ------------------------
# Include Clojure tools
Expand All @@ -43,7 +34,6 @@ resources/public/js

# ------------------------
# Frontend things
!cljs
!shadow-cljs.edn
!package.json
!bun.lockb
Expand All @@ -54,11 +44,6 @@ resources/public/js
!.gitignore
!.github/

# ------------------------
# Include ClojureScript Figwheel
!figwheel-main.edn
!*.cljs.edn

# ------------------------
# Include deployment related files
!config
Expand Down
22 changes: 0 additions & 22 deletions CHANGELOG.md

This file was deleted.

33 changes: 2 additions & 31 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,5 @@
# ------------------------------------------
# Build and run Practicalli Gameboard API Service
#
# Author: Practicalli
#
# Builder image:
# Official Clojure Docker image with Java 17 (eclipse-temurin) and Clojure CLI
# https://hub.docker.com/_/clojure/
#
# Run-time image:
# Official Java Docker image with Java 17 (eclipse-temurin)
# https://hub.docker.com/_/eclipse-temurin
# ------------------------------------------


# ------------------------
# Setup Builder container

FROM clojure:temurin-17-alpine AS builder

# Set Clojure CLI version (defaults to latest release)
# ENV CLOJURE_VERSION=1.11.1.1413

# Create directory for project code (working directory)
RUN mkdir -p /build

Expand All @@ -40,14 +19,6 @@ RUN apk add --no-cache nodejs npm

RUN npm install


# ------------------------
# Test and Package application via Makefile
# `make all` calls `deps`, `test-ci`, `dist` and `clean` tasks
# using shared library cache mounted by pipeline process

RUN npx shadow-cljs release app

# `dist` task packages Clojure service as an uberjar
# - creates: /build/practicalli-gameboard-api-service.jar
# - uses command `clojure -T:build uberjar`
Expand Down Expand Up @@ -94,7 +65,7 @@ USER clojure

# Copy service archive file from Builder image
WORKDIR /app
COPY --from=builder /build/target/tools-ifs-parts-standalone.jar /app/
COPY --from=builder /build/target/parts-standalone.jar /app/

# Optional: Add System Integration testing scripts
# RUN mkdir -p /app/test-scripts
Expand Down Expand Up @@ -136,7 +107,7 @@ ENV JDK_JAVA_OPTIONS="-XshowSettings:system -XX:+UseContainerSupport -XX:MaxRAMP
# Start service using dumb-init and java run-time
# (overrides `jshell` entrypoint - default in eclipse-temuring image)
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
CMD ["java", "-jar", "/app/tools-ifs-parts-standalone.jar"]
CMD ["java", "-jar", "/app/parts-standalone.jar"]


# Docker Entrypoint documentation
Expand Down
25 changes: 15 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# - `:env/dev` to include `dev` directory on class path
# - `:env/test` to include `test` directory and libraries to support testing
# - `:test/run` to run kaocha kaocha test runner and supporting paths and dependencies
# - `:repl/rebel` to start a Rebel terminal UI
# - `:package/uberjar` to create an uberjar for the service
# - docker
# - mega-linter-runner
Expand All @@ -28,7 +27,8 @@
HELP-DESCRIPTION-SPACING := 24

# Tool variables
MEGALINTER_RUNNER = npx mega-linter-runner --flavor java --env "'MEGALINTER_CONFIG=.github/config/megalinter.yaml'" --remove-container
FORMATTER_RUNNER = bunx @chrisoakman/standard-clojure-style
MEGALINTER_RUNNER = bunx mega-linter-runner --flavor java --env "'MEGALINTER_CONFIG=.github/config/megalinter.yaml'" --remove-container
CLOJURE_TEST_RUNNER = clojure -M:test/env:test/run
CLOJURE_EXEC_TEST_RUNNER = clojure -X:test/env:test/run

Expand All @@ -48,15 +48,15 @@ help: ## Describe available tasks in Makefile
# ------------------------------------ #

# ------- Clojure Development -------- #
repl: ## Run Clojure REPL with rich terminal UI (Rebel Readline)
$(info --------- Run Rebel REPL ---------)
clojure -M:test/env:repl/reloaded
repl: ## Run Clojure REPL
$(info --------- Run REPL with Shadow ---------)
clojure -M -m shadow.cljs.devtools.cli clj-repl

deps: deps.edn ## Prepare dependencies for test and dist targets
$(info --------- Download test and service libraries ---------)
clojure -P -X:build

dist: build-uberjar ## Build and package Clojure service
dist: build-frontend build-uberjar ## Build and package Clojure service
$(info --------- Build and Package Clojure service ---------)

# Remove files and directories after build tasks
Expand Down Expand Up @@ -101,6 +101,10 @@ build-jar: ## Build a jar archive of Clojure project
$(info --------- Build library jar ---------)
clojure -T:build/task jar

build-frontend: ## Build shadow-cljs frontend app
$(info --------- Build frontend ---------)
clojure -M -m shadow.cljs.devtools.cli release frontend

build-uberjar: ## Build a uberjar archive of Clojure project & Clojure runtime
$(info --------- Build service Uberjar ---------)
clojure -T:build/task uberjar
Expand All @@ -111,16 +115,17 @@ build-clean: ## Clean build assets or given directory
# ------------------------------------ #

# ------- Code Quality --------------- #
pre-commit-check: format-check lint test ## Run format, lint and test targets
pre-commit-check: format lint test ## Run format, lint and test targets

format-check: ## Run cljstyle to check the formatting of Clojure code
format: ## Run cljstyle to check the formatting of Clojure code
$(info --------- standard-clojure-style-js Runner ---------)
standard-clj check .
$(FORMATTER_RUNNER) check .

format-fix: ## Run cljstyle and fix the formatting of Clojure code
$(info --------- standard-clojure-style-js Runner ---------)
standard-clj fix .
$(FORMATTER_RUNNER) fix .

# TODO: Reconsider how useful this is
lint: ## Run MegaLinter with custom configuration (node.js required)
$(info --------- MegaLinter Runner ---------)
$(MEGALINTER_RUNNER)
Expand Down
9 changes: 3 additions & 6 deletions build.clj
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
(def project-config
"Project configuration to support all tasks"
{:class-directory "target/classes"
:main-namespace 'tools.ifs/parts
:main-namespace 'parts/server
:project-basis (build-api/create-basis)
:uberjar-file "target/tools-ifs-parts-standalone.jar"})
:uberjar-file "target/parts-standalone.jar"})

(defn config
"Display build configuration"
Expand Down Expand Up @@ -63,7 +63,7 @@
(let [config (merge project-config options)
{:keys [class-directory main-namespace project-basis uberjar-file]} config]
(clean "target")
(build-api/copy-dir {:src-dirs ["src" "resources"]
(build-api/copy-dir {:src-dirs ["src/main" "resources" "public"]
:target-dir class-directory})

(build-api/compile-clj {:basis project-basis
Expand All @@ -74,6 +74,3 @@
:class-dir class-directory
:main main-namespace
:uber-file uberjar-file})))

;; End of Build tasks
;; ---------------------------------------------------------
Binary file modified bun.lockb
Binary file not shown.
32 changes: 0 additions & 32 deletions cljs/tools/ifs/parts/core.cljs

This file was deleted.

2 changes: 1 addition & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ name: "parts"

services:
# --- Clojure Service --- #
parts-ifs-tools:
parts:
platform: linux/amd64
# Build using Dockerfile - relative path or Git repository
build:
Expand Down
Loading

0 comments on commit 3bfeb5e

Please sign in to comment.