Add docker
This commit is contained in:
parent
2e529cede8
commit
4db1154ecd
3 changed files with 154 additions and 14 deletions
|
@ -1,7 +1,8 @@
|
||||||
.fleet/
|
Dockerfile
|
||||||
.idea/
|
.dockerignore
|
||||||
dist/
|
node_modules
|
||||||
node_modules/
|
npm-debug.log
|
||||||
dist/
|
README.md
|
||||||
.DS_Store/
|
.output
|
||||||
|
.vinxi
|
||||||
|
.git
|
||||||
|
|
53
Dockerfile
53
Dockerfile
|
@ -1,11 +1,50 @@
|
||||||
FROM node:lts AS build
|
FROM node:21-alpine AS base
|
||||||
|
|
||||||
|
# Install dependencies only when needed
|
||||||
|
FROM base AS deps
|
||||||
|
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
|
||||||
|
RUN apk add --no-cache libc6-compat
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY package*.json ./
|
|
||||||
RUN npm install
|
# Install dependencies based on the preferred package manager
|
||||||
|
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
|
||||||
|
RUN \
|
||||||
|
if [ -f package-lock.json ]; then npm ci; \
|
||||||
|
elif [ -f pnpm-lock.yaml ]; then npm install --global pnpm && pnpm i --frozen-lockfile; \
|
||||||
|
else echo "Lockfile not found." && exit 1; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Rebuild the source code only when needed
|
||||||
|
FROM base AS builder
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
FROM nginx:alpine AS runtime
|
# Production image, copy all the files and run next
|
||||||
COPY ./nginx/nginx.conf /etc/nginx/nginx.conf
|
FROM base AS runner
|
||||||
COPY --from=build /app/dist /usr/share/nginx/html
|
WORKDIR /app
|
||||||
EXPOSE 8080
|
|
||||||
|
ENV NODE_ENV production
|
||||||
|
|
||||||
|
RUN addgroup --system --gid 1001 nodejs
|
||||||
|
RUN adduser --system --uid 1001 solidjs
|
||||||
|
|
||||||
|
COPY --from=builder /app/public ./public
|
||||||
|
|
||||||
|
COPY --from=builder --chown=solidjs:nodejs /app/.output ./.output
|
||||||
|
COPY --from=builder --chown=solidjs:nodejs /app/.vinxi ./.vinxi
|
||||||
|
|
||||||
|
RUN npm install vinxi
|
||||||
|
|
||||||
|
USER solidjs
|
||||||
|
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
ENV PORT 3000
|
||||||
|
# set hostname to localhost
|
||||||
|
ENV HOSTNAME "0.0.0.0"
|
||||||
|
|
||||||
|
CMD ["npx", "vinxi", "start"]
|
||||||
|
|
100
docker.sh
Executable file
100
docker.sh
Executable file
|
@ -0,0 +1,100 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Script: your_script.sh
|
||||||
|
# Description: Brief description of what the script does.
|
||||||
|
# Usage: ./your_script.sh [options]
|
||||||
|
# Options:
|
||||||
|
# -h, --help Display this help message
|
||||||
|
# -o, --option Specify an option
|
||||||
|
|
||||||
|
# Function to display usage information
|
||||||
|
function show_usage() {
|
||||||
|
echo "Usage: $0 [options]"
|
||||||
|
echo "Options:"
|
||||||
|
echo " -h, --help Display this help message"
|
||||||
|
echo " -d, --deploy Delete possibly old images and container and deploy a new container"
|
||||||
|
echo " -f, --follow If deployed will follow the log output"
|
||||||
|
echo " -s, --stay If deployed will leave the container running instead of stopping it"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check for the number of arguments
|
||||||
|
# if [ "$#" -eq 0 ]; then
|
||||||
|
# show_usage
|
||||||
|
# exit 1
|
||||||
|
# fi
|
||||||
|
|
||||||
|
# Parse command-line options
|
||||||
|
while [[ "$#" -gt 0 ]]; do
|
||||||
|
case $1 in
|
||||||
|
-h|--help)
|
||||||
|
show_usage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
-d|--deploy)
|
||||||
|
deploy=true
|
||||||
|
;;
|
||||||
|
-f|--follow)
|
||||||
|
follow=true
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unknown option: $1"
|
||||||
|
show_usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
image_name="solidjs-docker"
|
||||||
|
container_name="solidjs"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if [ $deploy ]; then
|
||||||
|
# Check if the container exists
|
||||||
|
if [ "$(docker ps -a -q -f name=$container_name)" ]; then
|
||||||
|
if [ "$(docker ps -q -f name=$container_name)" ]; then
|
||||||
|
# Container exists, stop and remove it
|
||||||
|
echo "Stopping and removing existing container..."
|
||||||
|
echo "Stopped $(docker stop $container_name)"
|
||||||
|
else
|
||||||
|
echo "Removing existing container..."
|
||||||
|
fi
|
||||||
|
echo "Removed $(docker rm $container_name)"
|
||||||
|
|
||||||
|
|
||||||
|
docker rmi $(docker images -q $image_name)
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Run Docker container in the background and capture container ID
|
||||||
|
docker build -t $image_name .
|
||||||
|
|
||||||
|
if [ $deploy ]; then
|
||||||
|
container_id=$(docker run --name $container_name -p 3000:3000 -d $image_name)
|
||||||
|
echo "Container deployed: $container_id"
|
||||||
|
elif [ !$follow ]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Function to display a message after interrupt
|
||||||
|
function exit_handler() {
|
||||||
|
# Clear the current line
|
||||||
|
echo -e "\033[2K"
|
||||||
|
|
||||||
|
if [ $stay ]; then
|
||||||
|
echo "Container is still running. To stop it, use:"
|
||||||
|
echo "docker stop $container_id"
|
||||||
|
else
|
||||||
|
echo "Stopping the container ..."
|
||||||
|
docker stop $container_id
|
||||||
|
echo "Stopped."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Register the exit_handler function to be called when the script receives the INT signal (Ctrl+C)
|
||||||
|
trap exit_handler INT
|
||||||
|
|
||||||
|
# Run Docker logs on the specified container
|
||||||
|
docker logs -f $container_id
|
Loading…
Reference in a new issue