-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
13503f9
commit a8bd09d
Showing
3 changed files
with
22 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,4 @@ | ||
.dockerignore | ||
.editorconfig | ||
.env | ||
.git | ||
.github | ||
.gitignore | ||
.idea | ||
.yarn | ||
.vscode | ||
coverage* | ||
tools | ||
LICENSE | ||
README.md | ||
node_modules | ||
* | ||
!dist | ||
!package.json | ||
!yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,29 @@ | ||
########################################################### | ||
## ## | ||
## Global variables ## | ||
## ## | ||
########################################################### | ||
# Can not go higher than 3.15 until this answer is updated: https://stackoverflow.com/a/38433396/3593896 | ||
FROM alpine:3.15 | ||
|
||
# see all versions at https://hub.docker.com/r/oven/bun/tags | ||
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 | ||
|
||
# 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" | ||
|
||
# Ensure we treat everything as production | ||
ENV NODE_ENV="production" | ||
|
||
# Pacakage management happens through Node and Yarn | ||
RUN curl https://get.volta.sh | bash | ||
ENV VOLTA_HOME "/root/.volta" | ||
ENV PATH "$VOLTA_HOME/bin:$PATH" | ||
|
||
# Copy only relevant files | ||
COPY package.json yarn.lock .yarnrc.yml tsconfig.json vitest.config.ts .prettier* .eslint* .cspell.json /app/ | ||
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 \ | ||
&& 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 \ | ||
&& 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 \ | ||
&& echo "node modules size after production focus: $(du -sh node_modules)" | ||
|
||
########################################################### | ||
## ## | ||
## PRODUCTION ## | ||
## ## | ||
########################################################### | ||
|
||
# Must be compatible with executable from Builder | ||
FROM debian:buster-slim | ||
# Install glibc. Alpine comes with `musl libc`, but Bun builds for `glibc` | ||
RUN apk --no-cache add ca-certificates wget \ | ||
&& wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \ | ||
&& wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.28-r0/glibc-2.28-r0.apk \ | ||
&& apk add glibc-2.28-r0.apk \ | ||
&& rm -f glibc-2.28-r0.apk | ||
|
||
# Open Container Initiative (OCI) labels | ||
LABEL org.opencontainers.image.title="Automation Standalone" \ | ||
LABEL org.opencontainers.image.title="Docker Standalone" \ | ||
org.opencontainers.image.description="This image contains an end-users automations application that communicates directly with a HomeAssistant instance" \ | ||
org.opencontainers.image.version="1.0.0" \ | ||
org.opencontainers.image.url="https://github.com/digital-alchemy/automation-standalone" \ | ||
org.opencontainers.image.url="https://github.com/digital-alchemy/docker-standalone" \ | ||
org.opencontainers.image.documentation="https://docs.digital-alchemy.app/" \ | ||
org.opencontainers.image.source="https://github.com/digital-alchemy/automation-standalone" \ | ||
org.opencontainers.image.source="https://github.com/digital-alchemy/docker-standalone" \ | ||
org.opencontainers.image.vendor="Digital Alchemy" \ | ||
org.opencontainers.image.authors="Webber Takken <[email protected]>" \ | ||
org.opencontainers.image.licenses="MIT" | ||
|
||
# Simplicity first | ||
# Install the application | ||
ENV NODE_ENV="production" | ||
|
||
WORKDIR /app | ||
|
||
# Copy the distributable files and production specific dependencies | ||
COPY --from=builder /app/dist /app/package.json ./ | ||
COPY package.json yarn.lock dist/server /app/ | ||
|
||
# Run the app | ||
EXPOSE 3000 | ||
CMD ["./server"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters