-
-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor docker image and CI pipeline #1624
base: master
Are you sure you want to change the base?
Changes from 15 commits
d267051
da19113
9e00685
d636bfb
bf5ca74
5fbc461
b62b9d3
92327e9
cfeb1bf
d37a9f3
528a1c0
2bddf77
d7f1a04
2700269
5e4c63c
efff286
c39a7ab
1ecd506
36c7690
bba12ac
d1a1f7e
de384b6
14092a1
90788bf
145f284
548a9e9
57f5775
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
data/* | ||
!data/scores.json | ||
**/.git | ||
**/.github | ||
data | ||
built | ||
doc | ||
node_modules | ||
frontend/lib | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed Added ignores for |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,49 +13,28 @@ on: | |
- '**.md' | ||
|
||
jobs: | ||
test: | ||
name: Run tests | ||
|
||
strategy: | ||
matrix: | ||
node_version: | ||
- 12 | ||
- 14 | ||
verify: | ||
name: Verify | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup | ||
uses: actions/[email protected] | ||
with: | ||
node-version: ${{matrix.node_version}} | ||
|
||
- name: Install | ||
run: npm install | ||
|
||
- name: Test | ||
run: npm test | ||
|
||
|
||
docker: | ||
name: Test docker image | ||
fetch-depth: 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setting |
||
|
||
runs-on: ubuntu-latest | ||
- name: Build | ||
run: make docker | ||
|
||
continue-on-error: true | ||
- name: Lint | ||
run: make docker-lint | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Build | ||
run: docker build --tag dr4ft-app . | ||
- name: Test | ||
run: make docker-test | ||
|
||
- name: Run | ||
run: docker run -dp 1337:1337 dr4ft-app | ||
- name: Run docker image | ||
run: make docker-run | ||
|
||
- name: Show info | ||
run: | | ||
|
@@ -64,24 +43,6 @@ jobs: | |
docker ps -a | ||
echo | ||
docker images | ||
echo | ||
make docker-logs FOLLOW= | ||
|
||
|
||
lint: | ||
name: Run ESLint | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup | ||
uses: actions/[email protected] | ||
with: | ||
node-version: 12 | ||
|
||
- name: Install | ||
run: npm install --ignore-scripts | ||
|
||
- name: Run ESLint | ||
run: npm run lint |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v12 | ||
16.15.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,40 @@ | ||
FROM node:lts-alpine | ||
ENV NPM_CONFIG_LOGLEVEL warn | ||
FROM node:16.15.0-alpine | ||
|
||
ARG VERSION_INFO=noVersion | ||
|
||
# Install "git" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Installing |
||
RUN apk update \ | ||
&& apk add alpine-sdk | ||
ENV NPM_CONFIG_LOGLEVEL warn | ||
ENV PORT=1337 | ||
|
||
# Set working dir as /app | ||
WORKDIR /app | ||
|
||
# Add sources to /app | ||
COPY . . | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Running |
||
COPY LICENSE . | ||
COPY .gitignore . | ||
COPY .babelrc . | ||
COPY .eslintrc.js . | ||
COPY .mocharc.yaml . | ||
COPY package.json . | ||
COPY package-lock.json . | ||
COPY webpack.prod.js . | ||
COPY webpack.common.js . | ||
COPY webpack.dev.js . | ||
COPY app.json . | ||
COPY app.js . | ||
COPY config/ config/ | ||
COPY scripts/ scripts/ | ||
COPY backend/ backend/ | ||
COPY frontend/ frontend/ | ||
|
||
RUN adduser -S dr4ftuser | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Node images already include a non-root user called |
||
RUN chown dr4ftuser -R . | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Running |
||
USER dr4ftuser | ||
|
||
# Install the dependencies | ||
RUN npm install | ||
RUN npm ci --ignore-scripts | ||
|
||
# Publish the port 1337 | ||
EXPOSE 1337 | ||
ENV VERSION_INFO=$VERSION_INFO | ||
RUN npm run postinstall | ||
|
||
# Run the server | ||
ENTRYPOINT [ "npm", "start" ] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
VERSION_INFO ?= $$(git describe --tags) | ||
IMAGE ?= dr4ft-app | ||
CONTAINER ?= $(IMAGE)-container | ||
PORT ?= 1337 | ||
|
||
|
||
# Show makefile help by default | ||
.DEFAULT_GOAL = help | ||
|
||
|
||
.PHONY: docker | ||
docker: ## Build docker image | ||
@echo "Building with version info $(VERSION_INFO)" | ||
docker build \ | ||
--build-arg VERSION_INFO=$(VERSION_INFO) \ | ||
-t $(IMAGE) . | ||
|
||
|
||
.PHONY: docker-run | ||
docker-run: docker-stop docker ## Run app in docker container | ||
docker run -d \ | ||
--name $(CONTAINER) \ | ||
--env "PORT=$(PORT)" \ | ||
-p $(PORT):$(PORT) \ | ||
$(IMAGE) | ||
@echo "##########################################" | ||
@echo "Dr4ft now running at http://localhost:$(PORT)" | ||
@echo "##########################################" | ||
|
||
|
||
.PHONY: docker-stop | ||
docker-stop: ## Stop running docker container | ||
docker stop $(CONTAINER) > /dev/null 2>&1 || true | ||
docker container rm $(CONTAINER) > /dev/null 2>&1 || true | ||
|
||
|
||
.PHONY: docker-logs | ||
FOLLOW := -f | ||
docker-logs: ## Show logs from running docker container | ||
docker logs $(FOLLOW) $(CONTAINER) | ||
|
||
|
||
.PHONY: docker-test | ||
docker-test: docker ## Run tests in docker container | ||
docker run --rm \ | ||
--entrypoint npm \ | ||
$(IMAGE) run test:js | ||
|
||
|
||
.PHONY: docker-lint | ||
docker-lint: docker ## Lint code in docker container | ||
docker run --rm \ | ||
--entrypoint npm \ | ||
$(IMAGE) run lint | ||
|
||
|
||
.PHONY: docker-clean | ||
docker-clean: docker-stop ## Remove any built docker images | ||
docker rmi -f $$(docker images -q $(IMAGE)) > /dev/null 2>&1 || true | ||
|
||
|
||
# Output help string for each target. | ||
# With thanks to: https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html | ||
.PHONY: help | ||
help: ## Show this help | ||
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,6 +110,6 @@ | |
"webpack-cli": "^4.9.2" | ||
}, | ||
"engines": { | ||
"node": "^12.16.3" | ||
"node": "^16.15.0" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, the
.git
folder was added to the docker image for the sake of building in a version number, namely a commit hash to display in the footer. Now that version number is built in as an environment variable. The other ignores here leave out files that are irrelevant to the docker image build. Any time these files changed required the entire image to be rebuilt.