Skip to content

Commit

Permalink
project cleanup (#2)
Browse files Browse the repository at this point in the history
* project cleanup

- Removed un-needed files. (changelog.md, doc/intro.md)
- Additional entries to gitignore and sorted contents.
- New make target to run container in detached mode.
- Bumped dependencies and project versions, organized project.clj into sections.
- Organized readme so build/run sections for both lein/jar and docker were together. Added example output from routes.
- Moved gen-class before require in ns's.
- Updated github actions workflow to test on jdk lts versions and use less, more generalized steps.
  • Loading branch information
wdhowe authored Jan 26, 2024
1 parent dfa0bec commit f466eb3
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 85 deletions.
19 changes: 10 additions & 9 deletions .github/workflows/clojure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,22 @@ jobs:

strategy:
matrix:
jdk_version: [11]
# JDK LTS: 8, 11, 17
jdk_version: [8, 11, 17]
os: [ubuntu-latest]

container:
image: clojure:openjdk-${{ matrix.jdk_version }}-lein

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
21 changes: 11 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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/
33 changes: 0 additions & 33 deletions CHANGELOG.md

This file was deleted.

4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
121 changes: 107 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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
3 changes: 0 additions & 3 deletions doc/intro.md

This file was deleted.

27 changes: 17 additions & 10 deletions project.clj
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions src/http_service_lein/config.clj
Original file line number Diff line number Diff line change
@@ -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."
Expand Down
4 changes: 2 additions & 2 deletions src/http_service_lein/core.clj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
(ns http-service-lein.core
(:gen-class)
(:require [clojure.tools.logging :as log]
[compojure.core :as compojure]
[compojure.route :as route]
[http-service-lein.config :as cfg]
[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."
Expand Down
4 changes: 2 additions & 2 deletions src/http_service_lein/default.clj
Original file line number Diff line number Diff line change
@@ -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"))
Expand Down

0 comments on commit f466eb3

Please sign in to comment.