Skip to content

Commit 4d347d1

Browse files
committed
Added Docker Image
1 parent fe52cb6 commit 4d347d1

File tree

5 files changed

+134
-1
lines changed

5 files changed

+134
-1
lines changed

.dockerignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
node_modules
2+
npm-debug.log
3+
.git
4+
.gitignore
5+
README.md
6+
.env
7+
.nyc_output
8+
coverage
9+
.coverage
10+
tests
11+
*.test.js
12+
.github
13+
docs
14+
scripts
15+
__tests__
16+
jest.config.js
17+
.eslintrc.json
18+
.prettierrc
19+
.prettierignore

.github/workflows/docker-build.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- main
8+
pull_request:
9+
branches:
10+
- master
11+
- main
12+
release:
13+
types: [published]
14+
15+
env:
16+
REGISTRY: ghcr.io
17+
IMAGE_NAME: ${{ github.repository }}
18+
19+
jobs:
20+
build-and-push:
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: read
24+
packages: write
25+
id-token: write
26+
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
31+
- name: Install cosign
32+
if: github.event_name != 'pull_request'
33+
uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0
34+
with:
35+
cosign-release: 'v2.2.4'
36+
37+
- name: Set up Docker Buildx
38+
uses: docker/setup-buildx-action@v3
39+
40+
- name: Log into registry ${{ env.REGISTRY }}
41+
if: github.event_name != 'pull_request'
42+
uses: docker/login-action@v3
43+
with:
44+
registry: ${{ env.REGISTRY }}
45+
username: ${{ github.actor }}
46+
password: ${{ secrets.GITHUB_TOKEN }}
47+
48+
- name: Extract metadata (tags, labels) for Docker
49+
id: meta
50+
uses: docker/metadata-action@v5
51+
with:
52+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
53+
tags: |
54+
type=ref,event=branch
55+
type=ref,event=pr
56+
type=semver,pattern={{version}}
57+
type=semver,pattern={{major}}.{{minor}}
58+
type=semver,pattern={{major}}
59+
type=raw,value=latest,enable={{is_default_branch}}
60+
61+
- name: Build and push Docker image
62+
id: build-and-push
63+
uses: docker/build-push-action@v5
64+
with:
65+
context: .
66+
platforms: linux/amd64,linux/arm64
67+
push: ${{ github.event_name != 'pull_request' }}
68+
tags: ${{ steps.meta.outputs.tags }}
69+
labels: ${{ steps.meta.outputs.labels }}
70+
cache-from: type=gha
71+
cache-to: type=gha,mode=max
72+
73+
- name: Sign the published Docker image
74+
if: ${{ github.event_name != 'pull_request' }}
75+
env:
76+
TAGS: ${{ steps.meta.outputs.tags }}
77+
DIGEST: ${{ steps.build-and-push.outputs.digest }}
78+
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM node:21
2+
3+
WORKDIR /app
4+
COPY . /app
5+
RUN npm install
6+
CMD ["node","express.js"]

express.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,39 @@ import gistCard from "./api/gist.js";
77
import express from "express";
88

99
const app = express();
10-
app.listen(process.env.port || 9000);
10+
const port = process.env.PORT || process.env.port || 9000;
11+
12+
app.use((req, res, next) => {
13+
console.log(`${new Date().toISOString()} ${req.method} ${req.url}`);
14+
next();
15+
});
1116

1217
app.get("/", statsCard);
1318
app.get("/pin", repoCard);
1419
app.get("/top-langs", langCard);
1520
app.get("/wakatime", wakatimeCard);
1621
app.get("/gist", gistCard);
22+
23+
app.get("/health", (req, res) => {
24+
res.status(200).json({ status: "ok", timestamp: new Date().toISOString() });
25+
});
26+
27+
const server = app.listen(port, () => {
28+
console.log(`Server started on port ${port}, awaiting requests`);
29+
});
30+
31+
process.on("SIGTERM", () => {
32+
console.log("stopping, received SIGTERM signal");
33+
server.close(() => {
34+
console.log("server stopped gracefully");
35+
process.exit(0);
36+
});
37+
});
38+
39+
process.on("SIGINT", () => {
40+
console.log("stopping, received SIGINT signal");
41+
server.close(() => {
42+
console.log("server stopped gracefully");
43+
process.exit(0);
44+
});
45+
});

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"axios": "^1.11.0",
6565
"dotenv": "^17.2.0",
6666
"emoji-name-map": "^1.2.8",
67+
"express": "^4.21.1",
6768
"github-username-regex": "^1.0.0",
6869
"upgrade": "^1.1.0",
6970
"word-wrap": "^1.2.5"

0 commit comments

Comments
 (0)