Skip to content
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

Dev environment + Typescript + Variables Improvements #5

Merged
merged 13 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .devcontainer/devcontainer.json
ivanitskiy marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// For format details, see https://aka.ms/devcontainer.json.
{
"name": "njsacme",
"dockerComposeFile": ["../docker-compose.yml"],
"service": "node",
"workspaceFolder": "/app",
"shutdownAction": "stopCompose",
"customizations": {
"vscode": {
"extensions": [
"dbaeumer.vscode-eslint",
"ms-vsliveshare.vsliveshare",
"ms-azuretools.vscode-docker",
"esbenp.prettier-vscode"
]
}
}
}
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
Makefile
ivanitskiy marked this conversation as resolved.
Show resolved Hide resolved
18 changes: 18 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"rules": {
"@typescript-eslint/no-unused-vars": [
"warn",
{
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"caughtErrorsIgnorePattern": "^_"
}
]
},
"root": true
}
4 changes: 4 additions & 0 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# style settings, see https://prettier.io/docs/en/options.html
semi: false
singleQuote: true
trailingComma: es5
45 changes: 6 additions & 39 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,43 +1,10 @@

ARG NGINX_VERSION=1.24.0
ARG NJS_VERSION=0.7.12

FROM node:20.2.0-bullseye AS builder
ENV NODE_ENV=development
FROM node:18 AS builder
WORKDIR /app
COPY package.json package-lock.json* ./
COPY . .
ivanitskiy marked this conversation as resolved.
Show resolved Hide resolved
RUN npm ci
COPY ./.mocharc.js ./
COPY ./babel.config.js ./
COPY ./rollup.config.js ./
COPY ./tsconfig.json ./
COPY ./src ./src

RUN npm run build

FROM nginx:${NGINX_VERSION}
ARG NGINX_VERSION
ARG NJS_VERSION

# following installation steps from http://nginx.org/en/linux_packages.html#Debian
RUN --mount=type=cache,target=/var/cache/apt <<EOF
set -eux
export DEBIAN_FRONTEND=noninteractive
apt-get -qq update
apt-get -qq install --yes --no-install-recommends --no-install-suggests \
curl gnupg2 ca-certificates debian-archive-keyring
update-ca-certificates
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
| tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
gpg --dry-run --quiet --no-keyring --import --import-options import-show \
/usr/share/keyrings/nginx-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/mainline/debian $(echo $PKG_RELEASE | cut -f2 -d~) nginx" \
| tee /etc/apt/sources.list.d/nginx.list
apt-get -qq install --yes --no-install-recommends --no-install-suggests \
curl nginx-module-njs=${NGINX_VERSION}+${NJS_VERSION}-${PKG_RELEASE}
apt-get remove --purge --auto-remove --yes
rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/nginx.list
EOF
RUN mkdir -p /usr/lib/nginx/njs_modules
COPY --from=builder /app/dist/* /usr/lib/nginx/njs_modules/
FROM nginx:1.24.0
ivanitskiy marked this conversation as resolved.
Show resolved Hide resolved
COPY --from=builder /app/dist/acme.js /usr/lib/nginx/njs_modules/acme.js
COPY ./examples/nginx.conf /etc/nginx/nginx.conf
RUN mkdir /etc/acme
ivanitskiy marked this conversation as resolved.
Show resolved Hide resolved
56 changes: 27 additions & 29 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
GREP ?= $(shell command -v ggrep 2> /dev/null || command -v grep 2> /dev/null)
AWK ?= $(shell command -v gawk 2> /dev/null || command -v awk 2> /dev/null)
DOCKER ?= docker
PROJECT_NAME ?= njs-acme-experemental
PROJECT_NAME ?= njs-acme
GITHUB_REPOSITORY ?= nginxinc/$(PROJECT_NAME)
SRC_REPO := https://github.com/$(GITHUB_REPOSITORY)
CURRENT_DIR = $(shell pwd)
Expand All @@ -17,46 +17,44 @@ help:
$(AWK) 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-28s\033[0m %s\n", $$1, $$2}' | sort


.PHONY:
format: ## Run rustfmt
$Q echo "$(M) building in release mode for the current platform"


.PHONY:
build: ## Run npm run build
$Q echo "$(M) building in release mode for the current platform"
$Q npm run build

.PHONY:
build: ## Run npm run build
$Q echo "$(M) building in release mode for the current platform"
$Q npm run build

.PHONY: build-docker
build-docker: ## Build docker image
$(DOCKER) buildx build $(DOCKER_BUILD_FLAGS) -t $(PROJECT_NAME) .
.PHONY: docker-build
docker-build: ## Build docker image
$(DOCKER) build $(DOCKER_BUILD_FLAGS) -t $(PROJECT_NAME) .
ivanitskiy marked this conversation as resolved.
Show resolved Hide resolved


.PHONY: docker-copy
docker-copy: CONTAINER_ID=$(shell $(DOCKER) create $(PROJECT_NAME))
docker-copy: docker-build ## Copy the acme.js file out of the container and save in dist/
echo ${CONTAINER_ID}
$(DOCKER) cp ${CONTAINER_ID}:/usr/lib/nginx/njs_modules/acme.js dist/acme.js
$(DOCKER) rm -v ${CONTAINER_ID}

.PHONY: start-docker
start-docker: build # build-docker ## Start docker container

.PHONY: docker-nginx
docker-nginx: docker-build ## Start nginx container
$(DOCKER) run --rm -it -p 8000:8000 \
-e "NJS_ACME_DIR=/etc/nginx/examples" \
-v $(CURRENT_DIR)/examples:/etc/nginx/examples/ \
-v $(CURRENT_DIR)/dist:/etc/nginx/dist/ njs-acme-experemental nginx -c examples/nginx.conf
-e "NJS_ACME_DIR=/etc/acme" \
$(PROJECT_NAME)


.PHONY: start-docker
start-njs: build # build-docker ## Start docker container
.PHONY: docker-njs
docker-njs: docker-build ## Start nginx container and run `njs`
$(DOCKER) run --rm -it -p 8000:8000 \
-e "NJS_ACME_DIR=/etc/nginx/examples" \
-v $(CURRENT_DIR)/examples:/etc/nginx/examples/ \
-v $(CURRENT_DIR)/dist:/etc/nginx/dist/ njs-acme-experemental njs
-e "NJS_ACME_DIR=/etc/acme" \
$(PROJECT_NAME) njs


.PHONY: start-all
start-all: build ## Start all docker compose services
docker compose up -d
.PHONY: docker-devup
docker-devup: docker-build ## Start all docker compose services
$(DOCKER) compose up -d

.PHONY: reload-nginx
reload-nginx: build start-all ## Reload nginx
docker compose stop nginx && docker compose start nginx && docker compose logs -f nginx

.PHONY: docker-reload-nginx
docker-reload-nginx: ## Reload nginx
$(DOCKER) compose up -d --force-recreate nginx && $(DOCKER) compose logs -f nginx
Loading