Skip to content

Commit fef46ac

Browse files
authored
Merge pull request #1 from eins78/first-release
First release
2 parents ef86b67 + 743f88e commit fef46ac

10 files changed

Lines changed: 57 additions & 22 deletions

File tree

.dockerignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.git
22
/node_modules/
33
.env
4-
4+
README.md
55
Dockerfile
66
.dockerignore

.env-default

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
PORT=4444
2-
TITLE=Hello World!
2+
APP_TITLE=Hello World!
Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,49 @@
11
name: Docker Image Publish
22

33
on:
4+
schedule:
5+
- cron: "0 10 * * *"
46
push:
7+
branches:
8+
- "**"
9+
tags:
10+
- "v*.*.*"
11+
pull_request:
512
branches:
613
- "main"
714

815
jobs:
916
Deploy:
1017
runs-on: ubuntu-latest
1118
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v3
21+
22+
- name: Docker meta
23+
id: meta
24+
uses: docker/metadata-action@v4
25+
with:
26+
# list of Docker images to use as base name for tags
27+
images: |
28+
ghcr.io/${{ github.repository }}
29+
# generate Docker tags based on the following events/attributes
30+
tags: |
31+
type=schedule
32+
type=ref,event=branch
33+
type=ref,event=pr
34+
type=semver,pattern={{version}}
35+
type=semver,pattern={{major}}.{{minor}}
36+
type=semver,pattern={{major}}
37+
type=sha
38+
1239
- name: set up QEMU
1340
uses: docker/setup-qemu-action@v2
1441

1542
- name: set up Docker buildx
1643
uses: docker/setup-buildx-action@v2
1744

1845
- name: login to GitHub Container Registry
46+
if: github.event_name != 'pull_request'
1947
uses: docker/login-action@v1
2048
with:
2149
registry: ghcr.io
@@ -25,7 +53,7 @@ jobs:
2553
- name: build and push docker image
2654
uses: docker/build-push-action@v3
2755
with:
28-
push: true
29-
tags: |
30-
ghcr.io/${{ github.repository }}:git-commit-${{ github.sha }}
31-
ghcr.io/${{ github.repository }}:latest
56+
context: .
57+
push: ${{ github.event_name != 'pull_request' }}
58+
tags: ${{ steps.meta.outputs.tags }}
59+
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
ARG BASEIMAGE="node:18-alpine"
2-
32
FROM $BASEIMAGE as prod
43

54
WORKDIR /app
@@ -27,5 +26,7 @@ EXPOSE 7777
2726

2827
HEALTHCHECK CMD node --experimental-fetch --no-warnings bin/healthcheck.mjs || exit 1
2928

29+
ENV APP_TITLE="Hello Dockerfile!"
30+
3031
# start app
3132
CMD npm start

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ npm start
1919
## Run with `docker`
2020

2121
```bash
22-
IMG=hello-world-web
23-
PORT=8080
24-
docker build -t $IMG .
22+
IMG=ghcr.io/eins78/hello-world-web
23+
export PORT=8080
24+
export "APP_TITLE=Hello ${USER}@$(hostname -s)"!
25+
# downloads image from Github Container registry. to build from source:
26+
# docker build -t $IMG .
2527
# or: docker buildx build --load -t $IMG .
26-
docker run --rm -it -e 'TITLE=Hello Docker!' -e PORT -p $PORT:$PORT $IMG
28+
docker run --rm -it -e APP_TITLE -e PORT -p $PORT:$PORT $IMG
2729
```
2830

2931
## Run with `docker-compose`
@@ -53,13 +55,17 @@ This table also show the order of precendence (last wins, if applicable).
5355

5456
### Healthcheck
5557

58+
There is a healthcheck script that checks if the homepage is served with a non-error status.
59+
Note that the query parameter `?healthcheck` is used, but not handled specifically by the server,
60+
it just help to identifiy the healthcheck requests in logs.
61+
5662
* `GET https://localhost:${PORT}/?healthcheck`
5763
* Node.js script: `bin/healthcheck.mjs`
5864
* with `docker` and `docker-compose`, see
5965

6066
```sh
61-
container=hello-world-web-webserver-1
62-
docker inspect $container | jq '.[0].State.Health'
67+
ctr=hello-world-web-webserver-1
68+
docker inspect $ctr | jq '.[0].State.Health'
6369
```
6470

6571
## Development

VERSION.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
VERSION=1.0.0
2-
PRE_RELEASE=alpha.1
2+
PRE_RELEASE=

bin/healthcheck.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
const URL = process.env.HEALTHCHECK_URL || `http://localhost:${process.env.PORT || 9999}/\?healthcheck`;
44

55
function fail(error) {
6-
console.log(`FAIL: ${URL}\n${[error.message, error.cause].filter(Boolean).join("\n")}`);
6+
console.log(`FAIL: ${[URL, error.message, error.cause].filter((i) => i).join("\n")}`);
77
process.exit(1);
88
}
99

1010
process.on("uncaughtException", fail);
1111
process.on("unhandledRejection", fail);
1212

1313
const response = await fetch(URL);
14-
if (!response.ok) fail(await response.text());
14+
if (!response.ok) fail({ message: `HTTP status ${response.status}`, cause: await response.text() });
1515

1616
console.log(`OK: ${URL}`);

docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ services:
1515
retries: 3
1616
environment:
1717
- "PORT=${PORT}"
18-
- "TITLE=Hello docker-compose!"
18+
- "APP_TITLE=Hello docker-compose!"

public/stylesheets/style.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ body {
1717

1818
/* dark mode */
1919
body {
20-
background-color: rgba(0, 0, 0, 0.92);
21-
color: rgba(255, 255, 255, 0.86);
20+
background-color: #141414;
21+
color: #8fc2c7;
2222
}
2323
@media screen and (prefers-color-scheme: light) {
2424
body {
25-
background-color: rgba(255, 255, 255, 0.9);
26-
color: rgba(0, 0, 0, 0.95);
25+
background-color: #a1e5e8;
26+
color: #0a0c0c;
2727
}
2828
}
2929

routes/home.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const router = express.Router();
33
const htmlTemplate = require("../views/html");
44
const homeTemplate = require("../views/home");
55
const config = require("../config");
6-
const title = process.env.TITLE ?? "!!! MISSING $TITLE !!!";
6+
const title = process.env.APP_TITLE ?? "Hello World!";
77

88
/* GET home page. */
99
router.get("/", function (req, res, next) {

0 commit comments

Comments
 (0)