Skip to content

Commit 557e5b9

Browse files
authored
chore: add docker example, close #109 (#110)
1 parent efc6b98 commit 557e5b9

File tree

5 files changed

+70
-0
lines changed

5 files changed

+70
-0
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,19 @@ sha: COMMIT_INFO_SHA
5555
remote: COMMIT_INFO_REMOTE
5656
```
5757

58+
### For Docker containers
59+
60+
When running your application inside a Docker container, you should set these environment variables using `-e` syntax.
61+
62+
```shell
63+
$ docker run \
64+
-e COMMIT_INFO_BRANCH=develop \
65+
-e COMMIT_INFO_SHA=e5d9eb66474bc0b681da9240aa5a457fe17bc8f3 \
66+
<container name>
67+
```
68+
69+
See [docker-example](docker-example) for a full example.
70+
5871
## Individual methods
5972

6073
In addition to `commitInfo` this module also exposes individual promise-returning

docker-example/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM node:alpine
2+
WORKDIR /app
3+
COPY index.js /app
4+
ENTRYPOINT [ "node", "." ]

docker-example/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Docker example
2+
3+
Shows how to pass environment variables with Git commit information when starting a Docker container.
4+
5+
To see the example:
6+
7+
```text
8+
$ ./build.sh
9+
...
10+
11+
Successfully built 54bcfe1f016e
12+
Successfully tagged local/test:latest
13+
docker-example index.js
14+
{
15+
branch: 'develop',
16+
message: 'This is commit message',
17+
email: null,
18+
author: null,
19+
sha: 'e5d9eb66474bc0b681da9240aa5a457fe17bc8f3',
20+
remote: null
21+
}
22+
```
23+
24+
See [build.sh](build.sh) to see how we are passing the commit values as environment variables.
25+
26+
If you want to see debug messages, run the command with `DEBUG=commit-info` environment variable.
27+
28+
```text
29+
$ DEBUG=commit-info ./build.sh
30+
```

docker-example/build.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
set e+x
2+
3+
LOCAL_NAME=local/test
4+
5+
docker build -t $LOCAL_NAME .
6+
7+
# run the example with source code and node_modules
8+
# mapped from the parent folder
9+
# pass commit message and branch and sha using environment variable -e
10+
# you can pass all other COMMIT_INFO_* if needed
11+
# if the user wants to see debug messages, just pass the environment
12+
# variable DEBUG as is
13+
docker run \
14+
-v $PWD/../src:/app/src -v $PWD/../node_modules:/app/node_modules \
15+
-e COMMIT_INFO_BRANCH=develop \
16+
-e COMMIT_INFO_MESSAGE="This is commit message" \
17+
-e COMMIT_INFO_SHA=e5d9eb66474bc0b681da9240aa5a457fe17bc8f3 \
18+
-e DEBUG \
19+
local/test

docker-example/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
console.log('docker-example index.js')
2+
3+
const { commitInfo } = require('./src')
4+
commitInfo().then(console.log)

0 commit comments

Comments
 (0)