Skip to content

Commit

Permalink
🐳 Add docker files
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianpb committed Mar 4, 2024
1 parent ca2b7f0 commit fb17c5c
Show file tree
Hide file tree
Showing 11 changed files with 5,060 additions and 3,734 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.git
74 changes: 74 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#######################
# Step 1: Base target #
#######################
FROM node:20 as development

ARG NPM_VERBOSE
ARG port
ARG app_path

# Base dir /app
WORKDIR /$app_path

COPY package.json ./

RUN if [ -z "${NPM_VERBOSE}" ]; then\
npm install; \
else \
npm install --verbose; \
fi

VOLUME /${app_path}/src
VOLUME /${app_path}/dist
VOLUME /${app_path}/tests
VOLUME /${app_path}/data

COPY tsconfig.json ./

# Expose the listening port of your app
EXPOSE ${port}

CMD ["npm","run", "dev"]

##########################
# Step 3: "build" target #
##########################
FROM development as build
ARG app_path

WORKDIR /$app_path

ADD src ./src

COPY tsconfig.json ./

RUN npm run build && tar czvf dist.tar.gz dist

###############################
# Step 4: "production" target #
###############################
FROM node:20-alpine3.18 as production
ARG port
ARG app_path

WORKDIR /$app_path

COPY package.json ./
ADD tests ./tests
ADD data ./data

## Install production dependencies and clean cache
#RUN npm install --production && \
# npm cache clean --force

COPY --from=build /${app_path}/node_modules /${app_path}/node_modules
COPY --from=build /${app_path}/dist.tar.gz /${app_path}/

RUN apk --no-cache add curl tar && \
tar -zxvf dist.tar.gz && \
rm -rf dist.tar.gz && apk del tar

# Expose the listening port of your app
EXPOSE ${port}

CMD ["npm","run", "start"]
37 changes: 16 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,44 +1,39 @@
# Directory to save podcast
# Mopidy saves this in /var/lib/mopidy/media
export APP = rhasspyhandler
export APP_PATH := $(shell pwd)
export PODCAST_DIR=media
export NPM_VERBOSE ?= 1
export DEVICE=raspberry
export PORT=8000

dummy := $(shell touch artifacts)
include ./artifacts

${PODCAST_DIR}:
mkdir -p ${PODCAST_DIR}

node_modules:
npm install
build:
@export EXEC_ENV=production; \
docker compose build

build: node_modules ${PODCAST_DIR}
@echo "$(PODCAST_DIR)"
npm run build
dev:
@export EXEC_ENV=development; \
docker compose up --build

dev: node_modules ${PODCAST_DIR}
@echo "$(PODCAST_DIR)"
npm run dev
up: ${PODCAST_DIR}
@export EXEC_ENV=production; \
docker compose up

up: node_modules ${PODCAST_DIR}
@echo "$(PODCAST_DIR)"
npm run start

test: node_modules ${PODCAST_DIR}
@echo "$(PODCAST_DIR)"
test: ${PODCAST_DIR}
npm run test

clean:
rm -rf node_modules



# sync code
push:
rsync -avz --include 'dist' --exclude-from '.gitignore' * raspi:~/rhasspyhandler/
rsync -avz dist raspi:~/rhasspyhandler/

pull:
rsync -avz --exclude 'src' --exclude-from '.gitignore' --exclude 'Makefile' raspi:~/rhasspyhandler/* .
rsync -avz raspi:~/rhasspyhandler/rhasspy .


#./run-venv.sh --profile es
Expand Down
22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
services:
backend:
image: ${APP}
container_name: ${APP}
build:
context: .
target: ${EXEC_ENV}
args:
app_path: /${APP}
NPM_VERBOSE: ${NPM_VERBOSE}
environment:
- port=${PORT}
- app_path=${APP}
- PODCAST_DIR=${PODCAST_DIR}
- DEVICE=${DEVICE}
- PORT_MQTT=${PORT_MQTT}
- HOST_MQTT=${HOST_MQTT}
- HOST_MOPIDY=${HOST_MOPIDY}
- HOST_RHASSPY=${HOST_RHASSPY}
- HOST_SNAPCAST=${HOST_SNAPCAST}
volumes:
- ${APP_PATH}/src:/${APP}/src
Loading

0 comments on commit fb17c5c

Please sign in to comment.