Skip to content

Commit 30ffe20

Browse files
committedDec 5, 2023
Guide to Dockerize Doc Website
1 parent 9dc8c75 commit 30ffe20

File tree

8 files changed

+187
-0
lines changed

8 files changed

+187
-0
lines changed
 

‎.dockerignore

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
**/.classpath
2+
**/.dockerignore
3+
**/.env
4+
**/.git
5+
**/.gitignore
6+
**/.project
7+
**/.settings
8+
**/.toolstarget
9+
**/.vs
10+
**/.vscode
11+
**/*.*proj.user
12+
**/*.dbmdl
13+
**/*.jfm
14+
**/charts
15+
**/docker-compose*
16+
**/compose*
17+
**/Dockerfile*
18+
**/node_modules
19+
**/npm-debug.log
20+
**/obj
21+
**/secrets.dev.yaml
22+
**/values.dev.yaml
23+
LICENSE
24+
README.md

‎.vscode/launch.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Docker Node.js Launch",
5+
"type": "docker",
6+
"request": "launch",
7+
"preLaunchTask": "docker-run: debug",
8+
"platform": "node"
9+
}
10+
]
11+
}

‎.vscode/tasks.json

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"type": "docker-build",
6+
"label": "docker-build",
7+
"platform": "node",
8+
"dockerBuild": {
9+
"dockerfile": "${workspaceFolder}/Dockerfile",
10+
"context": "${workspaceFolder}",
11+
"pull": true
12+
}
13+
},
14+
{
15+
"type": "docker-run",
16+
"label": "docker-run: release",
17+
"dependsOn": [
18+
"docker-build"
19+
],
20+
"platform": "node"
21+
},
22+
{
23+
"type": "docker-run",
24+
"label": "docker-run: debug",
25+
"dependsOn": [
26+
"docker-build"
27+
],
28+
"dockerRun": {
29+
"env": {
30+
"DEBUG": "*",
31+
"NODE_ENV": "development"
32+
}
33+
},
34+
"node": {
35+
"enableDebugging": true
36+
}
37+
}
38+
]
39+
}

‎Dockerfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM node:lts-alpine
2+
ENV NODE_ENV=production
3+
WORKDIR /usr/src/app
4+
COPY ["package.json", "package-lock.json*", "npm-shrinkwrap.json*", "./"]
5+
RUN npm install
6+
RUN npm run build
7+
COPY . .
8+
EXPOSE 4321
9+
RUN chown -R node /usr/src/app
10+
USER node
11+
CMD ["npm", "start"]

‎docker-compose.debug.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: '3.4'
2+
3+
services:
4+
starlightdocumentationwebsite:
5+
image: starlightdocumentationwebsite
6+
build:
7+
context: .
8+
dockerfile: ./Dockerfile
9+
environment:
10+
NODE_ENV: development
11+
ports:
12+
- 4321:4321
13+
- 9229:9229
14+
command: ["node", "--inspect=0.0.0.0:9229", "index.js"]

‎docker-compose.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: '3.4'
2+
3+
services:
4+
starlightdocumentationwebsite:
5+
image: starlightdocumentationwebsite
6+
build:
7+
context: .
8+
dockerfile: ./Dockerfile
9+
environment:
10+
NODE_ENV: production
11+
ports:
12+
- 4321:4321

‎public/dockerimage.png

23.8 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
title: Dockerize the Documentation Website and Publish to GitHub
3+
---
4+
5+
To dockerize the Thoth Tech Documentation Website and publish it to GitHub packages, the following
6+
steps were followed.
7+
8+
## Create Docker Compose and Dockerfile
9+
10+
1. Fork the [ThothTech Documentation](https://github.com/thoth-tech/ThothTech-Documentation-Website)
11+
Repo on GitHub.
12+
2. Open the repository on your local machine using Visual Studio Code.
13+
3. Locate **View** on the toolbar and select **Command Palette** (this is usually located on the top
14+
left hand corner of VS Code).
15+
4. When Command Palette is selected, choose **Docker: Add Docker Files to Workspace**.
16+
5. In **Select Application Platform**, choose Node.js.
17+
6. In **Choose a package.json file** select package.json.
18+
7. Type 4321 as the port that the application/website listens on.
19+
8. Select **Yes** for **Include Optional Docker Compose Files**.
20+
9. Press Enter and Dockerfile and Docker Compase would be generated for your environment.
21+
22+
## Generate a Personal Access Token on GitHub
23+
24+
1. Navigate to Thoth Techs GitHub page.
25+
2. In the upper-right corner of any page, click your profile photo, then click Settings.
26+
3. In the left sidebar, click Developer settings.
27+
4. In the left sidebar, under Personal access tokens, click Tokens (classic).
28+
5. Select Generate new token, then click Generate new token (classic).
29+
6. In the "Note" field, give your token a descriptive name.
30+
7. To give your token an expiration, select Expiration, then choose a default option or click Custom
31+
to enter a date.
32+
8. Select the scopes you'd like to grant this token. For this implementation write.packages and
33+
delete.packages was assigned.
34+
9. Click Generate token.
35+
10. Copy the new token to your clipboard.
36+
37+
## Build Docker Image and Push to GitHub Container Registry
38+
39+
**NB: For this action you would need Docker Desktop to be installed on your desktop**.
40+
41+
1. Open Docker Desktop on your laptop
42+
2. On your terminal ensure you are in the directory that has your Dockerfile, run the below command
43+
44+
```
45+
docker login --username [Your-GitHub-Name] --password [The generated token] ghcr.io
46+
```
47+
48+
3. Build the docker image by running the below command.
49+
50+
```
51+
docker build . -t ghcr.io/kachi-okorie/documentationwebsite:latest
52+
```
53+
54+
4. Push image to GitHub
55+
56+
```
57+
docker push ghcr.io/kachi-okorie/documentationwebsite:latest
58+
```
59+
60+
You should now see the docker image being pushed to GitHub package. ![Dockerimage](/dockerimage.png)
61+
62+
## Test Image Pushed to GitHub
63+
64+
1. Run the below command to obtain the ID of the image running locally on your machine.
65+
2. Delete local image to ensure your run image from the remote GitHub repository. In the command
66+
below, **889** is the first 3 digits of my image ID.
67+
68+
```
69+
docker image rm 889 --force
70+
```
71+
72+
3. Run the below command to run the image remotely.
73+
74+
```
75+
docker run ghcr.io/kachi-okorie/documentationwebsite:latest
76+
```

0 commit comments

Comments
 (0)
Please sign in to comment.