From 5f3b592724e046f9d5e79e8b679431e32bc87c1c Mon Sep 17 00:00:00 2001 From: stwhite Date: Wed, 23 Oct 2024 12:49:43 -0500 Subject: [PATCH] Added a bunch of Docker crap but I think Dockerfile.build is all that matters --- .dockerignore | 3 +++ .env | 5 +---- Dockerfile | 7 +++++++ Dockerfile.build | 23 +++++++++++++++++++++++ Dockerfile.create | 20 ++++++++++++++++++++ Dockerfile.nginx | 4 ++++ Dockerfile.update | 18 ++++++++++++++++++ build.bash | 7 +++++++ src/Dockerfile | 29 ----------------------------- test.bash | 18 ++++++++++++++++++ 10 files changed, 101 insertions(+), 33 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 Dockerfile.build create mode 100644 Dockerfile.create create mode 100644 Dockerfile.nginx create mode 100644 Dockerfile.update create mode 100755 build.bash delete mode 100644 src/Dockerfile create mode 100644 test.bash diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..3d5ed1b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +node_modules +.git +*.log diff --git a/.env b/.env index a376ace..2d3f4c6 100644 --- a/.env +++ b/.env @@ -1,5 +1,2 @@ -# URL of the API -REACT_APP_API_URL=http://localhost:8080 +REACT_APP_API_URL=http://zbox.local:8080 -# Base URL of the webapp -REACT_APP_BASE_URL="/" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..dc24a16 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM node:18-alpine AS builder +WORKDIR /app +COPY package*.json ./ +RUN npm install +COPY .env . +COPY . . +CMD ["npm", "run", "build"] diff --git a/Dockerfile.build b/Dockerfile.build new file mode 100644 index 0000000..1f65d4f --- /dev/null +++ b/Dockerfile.build @@ -0,0 +1,23 @@ +# Stage 1: Install dependencies +FROM node:14 AS build-stage + +WORKDIR /app + +# Copy package.json and package-lock.json first to leverage caching +COPY package*.json ./ + +# Install dependencies +RUN npm install + +# Copy the rest of your application code +COPY .env . +COPY . . + +# Build the application +RUN npm run build + +# Final stage: nothing needed, just to complete the multi-stage +FROM scratch + +# Copy the build output from the previous stage to a directory +COPY --from=build-stage /app/build ./build \ No newline at end of file diff --git a/Dockerfile.create b/Dockerfile.create new file mode 100644 index 0000000..2be1d90 --- /dev/null +++ b/Dockerfile.create @@ -0,0 +1,20 @@ +# Dockerfile.create +FROM node:14 AS builder + +# Set working directory +WORKDIR /app + +# Copy package.json and package-lock.json +COPY package*.json ./ + +# Install dependencies +RUN npm install +RUN npm install -g serve + +# Copy the rest of the application code +COPY . . +COPY .env . + +RUN npm build . + +CMD ["serve", "-s", "build"] diff --git a/Dockerfile.nginx b/Dockerfile.nginx new file mode 100644 index 0000000..ea26fc5 --- /dev/null +++ b/Dockerfile.nginx @@ -0,0 +1,4 @@ +FROM nginx:alpine +COPY build /usr/share/nginx/html +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] diff --git a/Dockerfile.update b/Dockerfile.update new file mode 100644 index 0000000..f7f009d --- /dev/null +++ b/Dockerfile.update @@ -0,0 +1,18 @@ +# Dockerfile.update +FROM node:14 + +# Set working directory +WORKDIR /app + +# Copy package.json and package-lock.json +COPY package*.json ./ +ENV REACT_APP_API_URL=http://zbox.local:8080 + +# Install dependencies +RUN npm install + +# Copy the rest of the application code +COPY . . +COPY .env . + +CMD ["npm", "run", "build"] diff --git a/build.bash b/build.bash new file mode 100755 index 0000000..9f0369a --- /dev/null +++ b/build.bash @@ -0,0 +1,7 @@ +#!/bin/bash +# Create teh react-builder image +docker build -f Dockerfile.create -t react-builder:latest . +# Run the react-builder image with local build/ dir mounted +docker run -v $(pwd)/build:/app/build react-builder:latest +# create the nginx container: +docker build --no-cache -f Dockerfile.nginx -t boxes-fe:latest . diff --git a/src/Dockerfile b/src/Dockerfile deleted file mode 100644 index 042b2ca..0000000 --- a/src/Dockerfile +++ /dev/null @@ -1,29 +0,0 @@ -# Use an official Node runtime as the base image -FROM node:14 as build - -# Set the working directory in the container -WORKDIR /app - -# Copy package.json and package-lock.json -COPY package*.json ./ - -# Install dependencies -RUN npm install - -# Copy the rest of the application code -COPY . . - -# Build the app -RUN npm run build - -# Use nginx to serve the static files -FROM nginx:alpine - -# Copy the build output to replace the default nginx contents -COPY --from=build /app/build /usr/share/nginx/html - -# Expose port 80 -EXPOSE 80 - -# Start nginx -CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/test.bash b/test.bash new file mode 100644 index 0000000..b551d03 --- /dev/null +++ b/test.bash @@ -0,0 +1,18 @@ +#!/bin/bash + +# Set the username and password +USERNAME="boxuser" +PASSWORD="boxuser" +EMAIL="boxuser@r8z.us" + +# Set the database file and table name +DB_FILE="../boxes-api/data/boxes.db" +TABLE_NAME="users" + +# Generate the bcrypt encrypted password using htpasswd +ENCRYPTED_PASSWORD=$(htpasswd -bnBC 10 "" "$PASSWORD" | tr -d ':\n') + +# Insert the username and encrypted password into the database +sqlite3 "$DB_FILE" "INSERT INTO $TABLE_NAME (username, password, email) VALUES ('$USERNAME', '$ENCRYPTED_PASSWORD', '$EMAIL')" + +echo "Password encrypted and stored in the database."