Skip to content

Commit

Permalink
chore: type checks as part of the build
Browse files Browse the repository at this point in the history
  • Loading branch information
webbertakken committed Apr 19, 2024
1 parent 1b6ef99 commit 3ce1a99
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
"scripts": {
"dev": "bun --hot --watch src/main.ts",
"sync": "bun tools/scripts/upgrade-da-packages-and-write-types.ts",
"build": "docker build . -f tools/docker/Dockerfile -t automation-prod",
"build": "bun --env-file .env build:docker",
"build:dist": "bun build src/main.ts --target=bun --outfile=dist/server.js",
"build:docker": "docker build . -f tools/docker/Dockerfile --build-arg HASS_TOKEN=$HASS_TOKEN --build-arg HASS_BASE_URL=$HASS_BASE_URL -t automation-prod",
"start": "docker run --env-file .env automation-prod",
"test": "vitest",
"coverage": "vitest --coverage",
Expand Down
30 changes: 22 additions & 8 deletions tools/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,22 @@ ARG BUN_VERSION="1"
# see all versions at https://hub.docker.com/r/bitnami/node/tags
ARG NODE_VERSION="20"

# Build time secrets
ARG HASS_TOKEN
ARG HASS_BASE_URL

###########################################################
## ##
## BUILDER ##
## ##
###########################################################

#FROM bitnami/node:${NODE_VERSION} as builder
#FROM imbios/bun-node:latest-20-debian as builder

FROM bitnami/node:${NODE_VERSION} as builder

# Allow build time secrets in this image
ARG HASS_TOKEN
ARG HASS_BASE_URL

# Act as CI system: no interactive tty, no stdin/stdout, no watch processes
ENV CI="true"

Expand All @@ -38,17 +43,26 @@ COPY src/ /app/src/

# Build and pre-flight checks
RUN cd /app/ \
&& echo "node version: $(node --version)" \
&& echo "yarn version: $(yarn --version)" \
&& echo -e "/app/ folder:\n$(ls -alh)" \
&& yarn install --immutable \
&& yarn test \
&& yarn prettier --check . \
&& yarn lint \
# Note: Can not do typecheck unless we pass in credentials during build time
# && yarn types \
# && yarn typecheck \
&& if [ -n "$HASS_TOKEN" ] && [ -n "$HASS_BASE_URL" ]; then \
echo "HASS_TOKEN provided, running yarn typecheck"; \
yarn type-writer; \
yarn typecheck; \
else \
echo "HASS_TOKEN not provided, skipping yarn typecheck"; \
fi \
&& yarn build:dist \
&& du -sh node_modules \
&& echo -e "dist files:\n$(ls -alh dist | tail -n +4)" \
&& echo "dist size: $(du -sh dist)" \
&& echo "node_modules size including dev dependencies: $(du -sh node_modules)" \
&& yarn workspaces focus --production \
&& du -sh node_modules
&& echo "node modules size after production focus: $(du -sh node_modules)"

###########################################################
## ##
Expand Down

0 comments on commit 3ce1a99

Please sign in to comment.