Skip to content

Commit 1e58107

Browse files
authored
Merge pull request #149 from 64J0/64J0-1
Dockerize this application
2 parents 03e5b75 + e7a4cb0 commit 1e58107

4 files changed

Lines changed: 87 additions & 0 deletions

File tree

.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.husky/
2+
.vscode/
3+
node_modules/
4+
.gitignore
5+
LICENSE
6+
README.md

Dockerfile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# This Dockerfile is used to set up a container environment with all the required
2+
# tools to use this project. You only need to provide the necessary environment
3+
# variables, as described in the README.
4+
#
5+
# Docker version that I used: 20.10.17
6+
#
7+
# If you're interested in testing other base images, take a look at this reference:
8+
# https://github.com/BretFisher/nodejs-rocks-in-docker
9+
FROM node:16-bullseye-slim
10+
11+
ARG USERNAME=migrator
12+
ARG USER_UID=2000
13+
ARG USER_GID=$USER_UID
14+
15+
LABEL version="0.1.5"
16+
LABEL description="Migrate Issues, Wiki from gitlab to github."
17+
18+
WORKDIR /app
19+
20+
# Add a non-root user, so later we can explore methods to scale
21+
# privileges within this container.
22+
# https://code.visualstudio.com/remote/advancedcontainers/add-nonroot-user#_creating-a-nonroot-user
23+
RUN groupadd --gid $USER_GID $USERNAME
24+
RUN useradd --uid $USER_UID --gid $USER_GID -m $USERNAME
25+
RUN chown -R $USERNAME /app
26+
27+
# Copy the project contents to the container
28+
COPY --chown=$USERNAME . /app
29+
30+
USER $USERNAME
31+
32+
# Install dependencies
33+
RUN npm i
34+
35+
# Start the process
36+
ENTRYPOINT ["/bin/bash", "-c", "npm run start"]

Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
CONTAINER_IMAGE ?= node-gitlab-2-github
2+
CONTAINER_TAG ?= latest
3+
LOCAL_PWD = $(shell pwd)
4+
5+
.PHONY: build-image
6+
build-image: ##@docker Build the Docker image
7+
docker build -t $(CONTAINER_IMAGE):$(CONTAINER_TAG) .
8+
9+
.PHONY: docker-run
10+
docker-run:
11+
docker run $(CONTAINER_IMAGE):$(CONTAINER_TAG)
12+
13+
.PHONY: docker-run-bind
14+
docker-run-bind:
15+
docker run \
16+
--mount type=bind,source="$(LOCAL_PWD)/settings.ts",target="/app/settings.ts",readonly \
17+
$(CONTAINER_IMAGE):$(CONTAINER_TAG)

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,34 @@ The user must be a member of the project you want to copy. This user must be the
4040
1. edit settings.ts
4141
1. run `npm run start`
4242

43+
### Docker
44+
45+
If you don't have Node.js installed in your local environment and don't want to install it you can use the Dockerized approach.
46+
47+
1. Make sure that you have [Docker](https://docs.docker.com/engine/install/) installed in your computer. You can test running `docker version` in the terminal.
48+
1. `cp sample_settings.ts settings.ts`
49+
1. edit settings.ts
50+
1. `docker build -t node-gitlab-2-github:latest .`, or, you can use `make build-image`
51+
1. `docker run node-gitlab-2-github:latest`, or, you can use `make docker-run`
52+
53+
If you want to let it run in the background (detached mode), just use the following command:
54+
55+
1. `docker run -d node-gitlab-2-github:latest`
56+
57+
### Docker with bind mounts
58+
59+
In order to optimize the usage of the dockerized application, one can use the `bind mounts` feature of Docker ([Docker docs](https://docs.docker.com/storage/bind-mounts/)). This way, whenever you change the `settings.ts` file in the host environment it will change in the container filesystem as well.
60+
61+
The process to use this trick is pretty much the same we presented before, the only different is the addition of a flag in the docker command to tell it what is the directory/file to be bound.
62+
63+
1. Make sure that you have [Docker](https://docs.docker.com/engine/install/) installed in your computer. You can test running `docker version` in the terminal.
64+
1. `cp sample_settings.ts settings.ts`
65+
1. edit settings.ts
66+
1. `docker build -t node-gitlab-2-github:latest .`, or, you can use `make build-image`
67+
1. This command must work for **Linux** or **Mac**: `docker run --mount type=bind,source="$(pwd)/settings.ts",target="/app/settings.ts",readonly node-gitlab-2-github:latest`, or, you can use `make docker-run-bind`
68+
69+
* If you want to run this last command in the Windows environment, please consult the Docker documentation on how to solve the problem of the pwd command expanding incorrectly there - [Docker documentation - Topics for windows](https://docs.docker.com/desktop/troubleshoot/topics/#topics-for-windows).
70+
4371
## Where to find info for the `settings.ts`
4472

4573
### gitlab

0 commit comments

Comments
 (0)