diff --git a/.github/workflows/clojure.yml b/.github/workflows/clojure.yml index 3a37839..96554f6 100644 --- a/.github/workflows/clojure.yml +++ b/.github/workflows/clojure.yml @@ -13,7 +13,8 @@ jobs: strategy: matrix: - jdk_version: [11] + # JDK LTS: 8, 11, 17 + jdk_version: [8, 11, 17] os: [ubuntu-latest] container: @@ -21,13 +22,13 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Dependencies - run: lein deps - - name: Version - run: lein version - - name: Build - run: lein compile + - name: Info + run: | + lein version + - name: Package + run: | + lein deps + lein compile + lein uberjar - name: Tests run: lein test - - name: Package - run: lein uberjar diff --git a/.gitignore b/.gitignore index 9b7dfa9..75ecfdd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,15 @@ -/target -/classes +/.calva /checkouts -profiles.clj -pom.xml -pom.xml.asc -*.jar *.class -/.lein-* -/.nrepl-port -.calva/ -.hgignore +/classes +.clj-kondo/ .hg/ +.hgignore +*.jar +/.lein-* .lsp/ +/.nrepl-port +pom.xml.asc +profiles.clj +/target +.vscode/ diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index e18802b..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,33 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/). - -## [Unreleased] - -### Changed - -- Add a new arity to `make-widget-async` to provide a different widget shape. - -## [0.1.1] - 2021-04-10 - -### Changed - -- Documentation on how to make the widgets. - -### Removed - -- `make-widget-sync` - we're all async, all the time. - -### Fixed - -- Fixed widget maker to keep working when daylight savings switches over. - -## 0.1.0 - 2021-04-10 - -### Added - -- Files from the new template. -- Widget maker public API - `make-widget-sync`. - -[Unreleased]: https://github.com/your-name/http-service-lein/compare/0.1.1...HEAD -[0.1.1]: https://github.com/your-name/http-service-lein/compare/0.1.0...0.1.1 diff --git a/Makefile b/Makefile index bbed5c8..f5af846 100644 --- a/Makefile +++ b/Makefile @@ -69,6 +69,10 @@ docker-tag: docker-run: docker run --interactive --tty --rm --publish 8080:8080 --name testing $(BUILD_TAG) +# docker-run-detach - run the container detached +docker-run-detach: + docker run --detach --rm --publish 8080:8080 --name testing $(BUILD_TAG) + # docker-login - login to registry using vars if available, # otherwise interactive login. docker-login: diff --git a/README.md b/README.md index 529fa4c..41acce8 100644 --- a/README.md +++ b/README.md @@ -2,24 +2,21 @@ [![Build Status][gh-actions-badge]][gh-actions] [![Clojure version][clojure-v]](project.clj) -Http service template with Leiningen. +HTTP service template with Leiningen. -## Building +## Build and Run - lein/jar + +Building and running the http service using the lein project tools. ### Build Standalone Uberjar The standalone uberjar can be built with lein and run with the java -jar command. -* Clone the project -* Build the uberjar - - ```bash - lein uberjar - ``` - -## Running +Build the uberjar -Different ways to run the service. +```bash +lein uberjar +``` ### Run With Lein or Jar @@ -42,9 +39,46 @@ Different ways to run the service. * With the built uberjar ```bash - java -jar target/uberjar/http-service-lein-0.1.0-standalone.jar + java -jar target/uberjar/http-service-lein-1.0.0-standalone.jar ``` +## Build and Run - docker + +Building and running the http service with docker. + +### Build the Docker Image + +The docker image is built and tagged by running: + +```bash +make build +``` + +### Run Docker Container + +Different ways to run the development/testing container. + +* Run an interactive container. + * control+c to stop/remove the container. + + ```bash + make docker-run + ``` + +* Run a container and connect with a shell. + * Type "exit" to stop/remove the container. + + ```bash + make shell + ``` + +* Run a container in detached mode. + * Stop the container using "docker stop `CONTAINER ID`". It will be deleted upon stop. + + ```bash + make docker-run-detach + ``` + ## Client requests Send client requests to the running http-server. @@ -57,9 +91,68 @@ Available default routes are: * GET /config -> return json of the http-server env settings. * GET /healthy -> return json of the health check response. +### Examples + +Example output using [httpie](https://httpie.io/). + +help + +```bash +http http://localhost:8080/help +``` + +```bash +HTTP/1.1 200 OK +Content-Type: text/plain; charset=utf-8 +Date: Fri, 26 Jan 2024 02:19:36 GMT +Server: http-kit +content-length: 140 + +HTTP API (1.0.0). Send requests to: +GET /help -> This help dialog. +GET /config -> Config settings. +GET /healthy -> Application health check. +``` + +config + +```bash +http http://localhost:8080/config +``` + +```bash +HTTP/1.1 200 OK +Content-Type: application/json; charset=utf-8 +Date: Fri, 26 Jan 2024 02:20:30 GMT +Server: http-kit +content-length: 18 + +{ + "http-port": 8080 +} +``` + +healthy + +```bash +http http://localhost:8080/healthy +``` + +```bash +HTTP/1.1 200 OK +Content-Type: application/json; charset=utf-8 +Date: Fri, 26 Jan 2024 02:26:14 GMT +Server: http-kit +content-length: 16 + +{ + "healthy": true +} +``` + ## License -Copyright © 2021 Bill Howe +Copyright © 2021-2024 Bill Howe This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which is available at @@ -76,4 +169,4 @@ at `https://www.gnu.org/software/classpath/license.html`. [gh-actions-badge]: https://github.com/wdhowe/http-service-lein/workflows/ci%2Fcd/badge.svg [gh-actions]: https://github.com/wdhowe/http-service-lein/actions -[clojure-v]: https://img.shields.io/badge/clojure-1.10.3-blue.svg +[clojure-v]: https://img.shields.io/badge/clojure-1.11.1-blue.svg diff --git a/doc/intro.md b/doc/intro.md deleted file mode 100644 index d2100e7..0000000 --- a/doc/intro.md +++ /dev/null @@ -1,3 +0,0 @@ -# Introduction to http-service-lein - -TODO: write [great documentation](http://jacobian.org/writing/what-to-write/) diff --git a/project.clj b/project.clj index c5db283..baf965e 100644 --- a/project.clj +++ b/project.clj @@ -1,20 +1,27 @@ -(defproject http-service-lein "0.1.0" +(defproject http-service-lein "1.0.0" + + ;;; Project Metadata :description "Http service template with Leiningen." :url "https://github.com/wdhowe/http-service-lein" :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0" :url "https://www.eclipse.org/legal/epl-2.0/"} - :dependencies [[org.clojure/clojure "1.10.3"] - [org.clojure/tools.logging "1.1.0"] - [compojure "1.6.2"] + + ;;; Dependencies, Plugins + :dependencies [[org.clojure/clojure "1.11.1"] + [org.clojure/tools.logging "1.2.4"] + [compojure "1.7.0"] [environ "1.2.0"] - [http-kit "2.5.3"] - [ring/ring-defaults "0.3.2"] + [http-kit "2.7.0"] + [ring/ring-defaults "0.4.0"] [ring/ring-json "0.5.1"] [trptcolin/versioneer "0.2.0"]] :plugins [[lein-ring "0.12.5"]] - :ring {:handler http-service-lein.core/app} - :main ^:skip-aot http-service-lein.core - :target-path "target/%s" + + ;;; Profiles :profiles {:dev {:dependencies [[javax.servlet/servlet-api "2.5"] [ring/ring-mock "0.4.0"]]} - :uberjar {:aot :all}}) + :uberjar {:aot :all}} + + ;;; Running Project Code + :ring {:handler http-service-lein.core/app} + :main ^:skip-aot http-service-lein.core) diff --git a/src/http_service_lein/config.clj b/src/http_service_lein/config.clj index 835b602..e496e50 100644 --- a/src/http_service_lein/config.clj +++ b/src/http_service_lein/config.clj @@ -1,6 +1,6 @@ (ns http-service-lein.config - (:require [environ.core :as environ]) - (:gen-class)) + (:gen-class) + (:require [environ.core :as environ])) (def conf "Load server configuration from the environment." diff --git a/src/http_service_lein/core.clj b/src/http_service_lein/core.clj index 6d11162..eec0569 100644 --- a/src/http_service_lein/core.clj +++ b/src/http_service_lein/core.clj @@ -1,4 +1,5 @@ (ns http-service-lein.core + (:gen-class) (:require [clojure.tools.logging :as log] [compojure.core :as compojure] [compojure.route :as route] @@ -6,8 +7,7 @@ [http-service-lein.default :as default] [org.httpkit.server :as http-server] [ring.middleware.defaults :as ring-defaults] - [ring.middleware.json :as ring-json]) - (:gen-class)) + [ring.middleware.json :as ring-json])) (compojure/defroutes app-routes "HTTP paths are defined here." diff --git a/src/http_service_lein/default.clj b/src/http_service_lein/default.clj index 28da434..04475ad 100644 --- a/src/http_service_lein/default.clj +++ b/src/http_service_lein/default.clj @@ -1,8 +1,8 @@ (ns http-service-lein.default + (:gen-class) (:require [clojure.tools.logging :as log] [http-service-lein.config :as cfg] - [trptcolin.versioneer.core :as version]) - (:gen-class)) + [trptcolin.versioneer.core :as version])) (def version "Project version." (version/get-version "http-service-lein" "http-service-lein"))