initial commit - code moved to separate repo
This commit is contained in:
19
_deploy/demo.10.yml
Normal file
19
_deploy/demo.10.yml
Normal file
@ -0,0 +1,19 @@
|
||||
version: "3.1"
|
||||
services:
|
||||
nextjs-app:
|
||||
image: node:20.11.0-alpine #sachinvashist/nextjs-docker #
|
||||
# jitesoft/node-base
|
||||
# paketobuildpacks/nodejs
|
||||
ports:
|
||||
- "8005:3000"
|
||||
volumes:
|
||||
- /mnt/apps/docker_volumes/cart/app/next-cart-app:/app
|
||||
environment:
|
||||
- NODE_ENV=demo
|
||||
- DATABASE_URL=mysql://cart:cart2023@192.168.0.10:3306/cart
|
||||
#command: sh -c "apk update && apk add git && rm -rf /tmp/clone && git clone https://git.d-popov.com/popov/next-cart-app.git /tmp/clone && rm -rf /app/* && cp -R /tmp/clone/next-cart-app/* /app/ && rm -rf /tmp/clone && npm cache clean --force && rm -rf /app/node_modules /app/package-lock.json && npm --silent --prefix /app install /app && npx --prefix /app prisma generate && npm --prefix /app run test; tail -f /dev/null"
|
||||
#command: sh -c "rm -rf /tmp/clone && git clone https://git.d-popov.com/popov/next-cart-app.git /tmp/clone && rm -rf /app/* && cp -R /tmp/clone/next-cart-app/* /app/ && rm -rf /tmp/clone && npm cache clean --force && rm -rf /app/node_modules /app/package-lock.json && npm --silent --prefix /app install /app && npx --prefix /app prisma generate && npm --prefix /app run test; tail -f /dev/null"
|
||||
command: sh -c "npm cache clean --force && rm -rf /app/node_modules /app/package-lock.json && npm --silent --prefix /app install /app && npx --prefix /app prisma generate && npm --prefix /app run test; tail -f /dev/null"
|
||||
#command: npm run test; tail -f /dev/null
|
||||
tty: true
|
||||
stdin_open: true
|
14
_deploy/demo.11-demo.yml
Normal file
14
_deploy/demo.11-demo.yml
Normal file
@ -0,0 +1,14 @@
|
||||
version: "3.1"
|
||||
services:
|
||||
nextjs-app:
|
||||
image: node:20.11.0-alpine #sachinvashist/nextjs-docker #
|
||||
ports:
|
||||
- "5001:3000" # Map port 3000 from container to host
|
||||
volumes:
|
||||
- /mnt/apps/DEV/cart-demo:/app
|
||||
environment:
|
||||
- NODE_ENV=demo
|
||||
- DATABASE_URL=mysql://cart:cart2023@192.168.0.10:3306/cart
|
||||
command: sh -c " cd /app && npm run test; tail -f /dev/null"
|
||||
tty: true
|
||||
stdin_open: true
|
112
_deploy/deoloy.azure.prod.yml
Normal file
112
_deploy/deoloy.azure.prod.yml
Normal file
@ -0,0 +1,112 @@
|
||||
version: "3"
|
||||
services:
|
||||
nextjs-app: # https://sofia.mwhitnessing.com/
|
||||
hostname: jwpw-app # jwpw-nextjs-app-1
|
||||
image: docker.d-popov.com/jwpw:latest
|
||||
#ports:
|
||||
# - "3000:3000"
|
||||
volumes:
|
||||
- /mnt/docker_volumes/pw/app/public/content/uploads/:/app/public/content/uploads
|
||||
environment:
|
||||
- NODE_ENV=prod
|
||||
- TZ=Europe/Sofia
|
||||
#- DATABASE_URL=mysql://jwpwsofia:dwxhns9p9vp248V39xJyRthUsZ2gR9@mariadb:3306/jwpwsofia
|
||||
#- DATABASE_URL=postgres://jwpwsofia:dwxhns9p9vp248V39xJyRthUsZ2gR9@mariadb:3306/jwpwsofia
|
||||
- UPDATE_CODE_FROM_GIT=true # Set to true to pull latest code from Git
|
||||
- GIT_BRANCH=mariadb
|
||||
- GIT_USERNAME=deploy
|
||||
- GIT_PASSWORD=%L3Kr2R438u4F7^%40
|
||||
command: sh -c " cd /app && npm install && npm run nodeenv; tail -f /dev/null"
|
||||
#command: sh -c " cd /app && n
|
||||
tty: true
|
||||
stdin_open: true
|
||||
restart: always
|
||||
networks:
|
||||
- infrastructure_default
|
||||
mariadb:
|
||||
hostname: mariadb
|
||||
image: bitnami/mariadb:latest #mariadb:10.4
|
||||
volumes:
|
||||
- /mnt/docker_volumes/pw/data/mysql:/var/lib/mysql
|
||||
environment:
|
||||
MYSQL_DATABASE: jwpwsofia
|
||||
MYSQL_USER: jwpwsofia
|
||||
MYSQL_PASSWORD: dwxhns9p9vp248V39xJyRthUsZ2gR9
|
||||
#MARIADB_ROOT_PASSWORD: i4966cWBtP3xJ7BLsbsgo93C8Q5262
|
||||
MYSQL_ROOT_PASSWORD: i4966cWBtP3xJ7BLsbsgo93C8Q5262
|
||||
command:
|
||||
[
|
||||
"mysqld",
|
||||
"--max-connections=1000",
|
||||
"--sql-mode=ALLOW_INVALID_DATES,ANSI_QUOTES,ERROR_FOR_DIVISION_BY_ZERO,HIGH_NOT_PRECEDENCE,IGNORE_SPACE,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_BACKSLASH_ESCAPES,NO_DIR_IN_CREATE,NO_ENGINE_SUBSTITUTION,NO_FIELD_OPTIONS,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_UNSIGNED_SUBTRACTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ONLY_FULL_GROUP_BY,PIPES_AS_CONCAT,REAL_AS_FLOAT,STRICT_ALL_TABLES,STRICT_TRANS_TABLES,ANSI,DB2,MAXDB,MSSQL,MYSQL323,MYSQL40,ORACLE,POSTGRESQL,TRADITIONAL",
|
||||
"--wait-timeout=28800",
|
||||
]
|
||||
networks:
|
||||
- infrastructure_default
|
||||
|
||||
postgres:
|
||||
hostname: postgres
|
||||
image: postgres
|
||||
restart: always
|
||||
# set shared memory limit when using docker-compose
|
||||
shm_size: 128mb
|
||||
# or set shared memory limit when deploy via swarm stack
|
||||
#volumes:
|
||||
# - type: tmpfs
|
||||
# target: /dev/shm
|
||||
# tmpfs:
|
||||
# size: 134217728 # 128*2^20 bytes = 128Mb
|
||||
environment:
|
||||
POSTGRES_PASSWORD: i4966cWBtP3xJ7BLsbsgo93C8Q5262
|
||||
|
||||
networks:
|
||||
- infrastructure_default
|
||||
|
||||
# nextjs-app-staging: # https://sofia.mwhitnessing.com/
|
||||
# image: docker.d-popov.com/jwpw:latest
|
||||
# ports:
|
||||
# - "3000:3000"
|
||||
# volumes:
|
||||
# - /mnt/docker_volumes/pw/app/.env.sofia:/app/.env.prod
|
||||
# environment:
|
||||
# - NODE_ENV=demo
|
||||
# - TZ=Europe/Sofia
|
||||
# - DATABASE_URL=mysql://jwpwsofia:dwxhns9p9vp248V39xJyRthUsZ2gR9@mariadb:3306/jwpwsofia
|
||||
# - UPDATE_CODE_FROM_GIT=true # Set to true to pull latest code from Git
|
||||
# - GIT_USERNAME=deploy
|
||||
# - GIT_PASSWORD=%L3Kr2R438u4F7^%40
|
||||
# - NEXT_PUBLIC_HOST=demo.mwhitnessing.com
|
||||
# - NEXTAUTH_URL= https://demo.mwhitnessing.com
|
||||
# command: sh -c " cd /app && npm install && npm run nodeenv; tail -f /dev/null"
|
||||
# tty: true
|
||||
# stdin_open: true
|
||||
# restart: always
|
||||
# networks:
|
||||
# - infrastructure_default
|
||||
|
||||
mariadb_backup:
|
||||
image: alpine:latest
|
||||
volumes:
|
||||
- /mnt/docker_volumes/pw/data/backup:/backup
|
||||
# - ./gdrive_service_account.json:/root/.gdrive_service_account.json
|
||||
environment:
|
||||
MYSQL_USER: jwpwsofia
|
||||
MYSQL_PASSWORD: dwxhns9p9vp248V39xJyRthUsZ2gR9
|
||||
MYSQL_DATABASE: jwpwsofia
|
||||
MYSQL_HOST: mariadb
|
||||
# GOOGLE_DRIVE_FOLDER_ID: your_google_drive_folder_id
|
||||
entrypoint: /bin/sh -c
|
||||
|
||||
networks:
|
||||
- infrastructure_default
|
||||
command: |
|
||||
"apk add --no-cache mysql-client curl && \
|
||||
echo '* 2 * * * mysqldump -h $$MYSQL_HOST -P 3306 -u$$MYSQL_USER -p$$MYSQL_PASSWORD $$MYSQL_DATABASE > /backup/$$(date +\\%Y-\\%m-\\%d-\\%H\\%M\\%S)-$$MYSQL_DATABASE.sql' > /etc/crontabs/root && \
|
||||
crond -f -d 8"
|
||||
# wget -q https://github.com/prasmussen/gdrive/releases/download/2.1.0/gdrive-linux-x64 -O /usr/bin/gdrive && \
|
||||
# chmod +x /usr/bin/gdrive && \
|
||||
# gdrive about --service-account /root/.gdrive_service_account.json && \
|
||||
# echo '0 * * * * /usr/bin/mysqldump -h $$MYSQL_HOST -u$$MYSQL_USER -p$$MYSQL_PASSWORD $$MYSQL_DATABASE | gzip > /backup/$$(date +\\%Y-\\%m-\\%d-\\%H\\%M\\%S)-$$MYSQL_DATABASE.sql.gz && gdrive upload --parent $$GOOGLE_DRIVE_FOLDER_ID --service-account /root/.gdrive_service_account.json /backup/$$(date +\\%Y-\\%m-\\%d-\\%H\\%M\\%S)-$$MYSQL_DATABASE.sql.gz' > /etc/crontabs/root && crond -f -d 8"
|
||||
networks:
|
||||
infrastructure_default:
|
||||
external: true
|
39
_deploy/deoloy.azure.yml
Normal file
39
_deploy/deoloy.azure.yml
Normal file
@ -0,0 +1,39 @@
|
||||
version: "3"
|
||||
services:
|
||||
nextjs-app:
|
||||
image: node:20.11.0-alpine
|
||||
ports:
|
||||
- "3000:3000"
|
||||
working_dir: /app
|
||||
volumes:
|
||||
- /mnt/docker_volumes/pw/app:/app
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
- DATABASE_URL=mysql://jwpwsofia:dwxhns9p9vp248V39xJyRthUsZ2gR9@mariadb:3306/jwpwsofia
|
||||
command: /bin/sh -c "npm install && npm install -g dotenv-cli next && npx prisma generate && next dev; tail -f /dev/null" # Install dependencies and start the app
|
||||
#command: sh -c " cd /app && npm run prod; tail -f /dev/null"
|
||||
#HOST: fallocate -l 1G /swapfile && chmod 600 /swapfile && mkswap /swapfile && swapon /swapfile && echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
|
||||
# apk add git && rm -rf /tmp/clone && git clone --depth 1 https://git.d-popov.com/popov/next-cart-app.git /tmp/clone
|
||||
# cp -R /tmp/clone/next-cart-app/* /app/
|
||||
# rm -rf /tmp/clone
|
||||
# npm cache clean --force && rm -rf /app/node_modules /app/package-lock.json
|
||||
# npm --silent --prefix /app install /app && npx --prefix /app prisma generate && npm --prefix /app run test; tail -f /dev/null
|
||||
|
||||
tty: true
|
||||
stdin_open: true
|
||||
|
||||
mariadb:
|
||||
image: mariadb:10.6
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: i4966cWBtP3xJ7BLsbsgo93C8Q5262
|
||||
MYSQL_DATABASE: jwpwsofia
|
||||
MYSQL_USER: jwpwsofia
|
||||
MYSQL_PASSWORD: dwxhns9p9vp248V39xJyRthUsZ2gR9
|
||||
ports:
|
||||
- "3306:3306"
|
||||
volumes:
|
||||
- /mnt/docker_volumes/pw/data/mysql:/var/lib/mysql
|
||||
|
||||
volumes:
|
||||
nextjs-app-data:
|
||||
mysql-data:
|
27
_deploy/deploy.homelab.production.yml
Normal file
27
_deploy/deploy.homelab.production.yml
Normal file
@ -0,0 +1,27 @@
|
||||
version: "3.1"
|
||||
services:
|
||||
nextjs-app:
|
||||
image: docker.d-popov.com/jwpw:latest
|
||||
ports:
|
||||
- "5001:3000"
|
||||
environment:
|
||||
- NODE_ENV=prod
|
||||
- DATABASE_URL=mysql://cart:o74x642Rc8@mariadb:3306/cart
|
||||
- UPDATE_CODE_FROM_GIT=true # Set to true to pull latest code from Git
|
||||
- GIT_USERNAME=deploy
|
||||
- GIT_PASSWORD=%L3Kr2R438u4F7^%40
|
||||
command: sh -c " cd /app && npm install && npm run nodeenv; tail -f /dev/null"
|
||||
tty: true
|
||||
stdin_open: true
|
||||
mariadb:
|
||||
hostname: mariadb
|
||||
image: mariadb #bitnami/mariadb:latest #mariadb:10.4
|
||||
environment:
|
||||
MARIADB_ROOT_PASSWORD: Pw62L$3332JH
|
||||
MYSQL_ROOT_PASSWORD: Pw62L$3332JH
|
||||
MYSQL_DATABASE: cart
|
||||
MYSQL_USER: cart
|
||||
MYSQL_PASSWORD: o74x642Rc8
|
||||
networks:
|
||||
- default
|
||||
- mysql_default
|
34
_deploy/docker.init/.dockerignore
Normal file
34
_deploy/docker.init/.dockerignore
Normal file
@ -0,0 +1,34 @@
|
||||
# Include any files or directories that you don't want to be copied to your
|
||||
# container here (e.g., local build artifacts, temporary files, etc.).
|
||||
#
|
||||
# For more help, visit the .dockerignore file reference guide at
|
||||
# https://docs.docker.com/engine/reference/builder/#dockerignore-file
|
||||
|
||||
**/.classpath
|
||||
**/.dockerignore
|
||||
**/.env
|
||||
**/.git
|
||||
**/.gitignore
|
||||
**/.project
|
||||
**/.settings
|
||||
**/.toolstarget
|
||||
**/.vs
|
||||
**/.vscode
|
||||
**/.next
|
||||
**/.cache
|
||||
**/*.*proj.user
|
||||
**/*.dbmdl
|
||||
**/*.jfm
|
||||
**/charts
|
||||
**/docker-compose*
|
||||
**/compose*
|
||||
**/Dockerfile*
|
||||
**/node_modules
|
||||
**/npm-debug.log
|
||||
**/obj
|
||||
**/secrets.dev.yaml
|
||||
**/values.dev.yaml
|
||||
**/build
|
||||
**/dist
|
||||
LICENSE
|
||||
README.md
|
70
_deploy/docker.init/Dockerfile
Normal file
70
_deploy/docker.init/Dockerfile
Normal file
@ -0,0 +1,70 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
|
||||
# Comments are provided throughout this file to help you get started.
|
||||
# If you need more help, visit the Dockerfile reference guide at
|
||||
# https://docs.docker.com/engine/reference/builder/
|
||||
|
||||
ARG NODE_VERSION=18.17.1
|
||||
|
||||
################################################################################
|
||||
# Use node image for base image for all stages.
|
||||
FROM node:${NODE_VERSION}-alpine as base
|
||||
|
||||
# Set working directory for all build stages.
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
|
||||
################################################################################
|
||||
# Create a stage for installing production dependecies.
|
||||
FROM base as deps
|
||||
|
||||
# Download dependencies as a separate step to take advantage of Docker's caching.
|
||||
# Leverage a cache mount to /root/.npm to speed up subsequent builds.
|
||||
# Leverage bind mounts to package.json and package-lock.json to avoid having to copy them
|
||||
# into this layer.
|
||||
RUN --mount=type=bind,source=package.json,target=package.json \
|
||||
--mount=type=bind,source=package-lock.json,target=package-lock.json \
|
||||
--mount=type=cache,target=/root/.npm \
|
||||
npm ci --omit=dev
|
||||
|
||||
################################################################################
|
||||
# Create a stage for building the application.
|
||||
FROM deps as build
|
||||
|
||||
# Download additional development dependencies before building, as some projects require
|
||||
# "devDependencies" to be installed to build. If you don't need this, remove this step.
|
||||
RUN --mount=type=bind,source=package.json,target=package.json \
|
||||
--mount=type=bind,source=package-lock.json,target=package-lock.json \
|
||||
--mount=type=cache,target=/root/.npm \
|
||||
npm ci
|
||||
|
||||
# Copy the rest of the source files into the image.
|
||||
COPY . .
|
||||
# Run the build script.
|
||||
RUN npm run build
|
||||
|
||||
################################################################################
|
||||
# Create a new stage to run the application with minimal runtime dependencies
|
||||
# where the necessary files are copied from the build stage.
|
||||
FROM base as final
|
||||
|
||||
# Use production node environment by default.
|
||||
ENV NODE_ENV production
|
||||
|
||||
# Run the application as a non-root user.
|
||||
USER node
|
||||
|
||||
# Copy package.json so that package manager commands can be used.
|
||||
COPY package.json .
|
||||
|
||||
# Copy the production dependencies from the deps stage and also
|
||||
# the built application from the build stage into the image.
|
||||
COPY --from=deps /usr/src/app/node_modules ./node_modules
|
||||
COPY --from=build /usr/src/app/deploy ./deploy
|
||||
|
||||
|
||||
# Expose the port that the application listens on.
|
||||
EXPOSE 3000
|
||||
|
||||
# Run the application.
|
||||
CMD node server.js
|
51
_deploy/docker.init/compose.yaml
Normal file
51
_deploy/docker.init/compose.yaml
Normal file
@ -0,0 +1,51 @@
|
||||
# Comments are provided throughout this file to help you get started.
|
||||
# If you need more help, visit the Docker compose reference guide at
|
||||
# https://docs.docker.com/compose/compose-file/
|
||||
|
||||
# Here the instructions define your application as a service called "server".
|
||||
# This service is built from the Dockerfile in the current directory.
|
||||
# You can add other services your application may depend on here, such as a
|
||||
# database or a cache. For examples, see the Awesome Compose repository:
|
||||
# https://github.com/docker/awesome-compose
|
||||
services:
|
||||
server:
|
||||
build:
|
||||
context: .
|
||||
environment:
|
||||
NODE_ENV: production
|
||||
ports:
|
||||
- 3000:3000
|
||||
|
||||
# The commented out section below is an example of how to define a PostgreSQL
|
||||
# database that your application can use. `depends_on` tells Docker Compose to
|
||||
# start the database before your application. The `db-data` volume persists the
|
||||
# database data between container restarts. The `db-password` secret is used
|
||||
# to set the database password. You must create `db/password.txt` and add
|
||||
# a password of your choosing to it before running `docker-compose up`.
|
||||
# depends_on:
|
||||
# db:
|
||||
# condition: service_healthy
|
||||
# db:
|
||||
# image: postgres
|
||||
# restart: always
|
||||
# user: postgres
|
||||
# secrets:
|
||||
# - db-password
|
||||
# volumes:
|
||||
# - db-data:/var/lib/postgresql/data
|
||||
# environment:
|
||||
# - POSTGRES_DB=example
|
||||
# - POSTGRES_PASSWORD_FILE=/run/secrets/db-password
|
||||
# expose:
|
||||
# - 5432
|
||||
# healthcheck:
|
||||
# test: [ "CMD", "pg_isready" ]
|
||||
# interval: 10s
|
||||
# timeout: 5s
|
||||
# retries: 5
|
||||
# volumes:
|
||||
# db-data:
|
||||
# secrets:
|
||||
# db-password:
|
||||
# file: db/password.txt
|
||||
|
35
_deploy/entrypoint.sh
Normal file
35
_deploy/entrypoint.sh
Normal file
@ -0,0 +1,35 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ "$UPDATE_CODE_FROM_GIT" = "true" ]; then
|
||||
apk add git nano rsync
|
||||
echo "Updating code from git.d-popov.com...(as '$GIT_USERNAME')"
|
||||
rm -rf /tmp/clone
|
||||
mkdir /tmp/clone
|
||||
|
||||
git clone -b ${GIT_BRANCH:-master} --depth 1 https://$GIT_USERNAME:${GIT_PASSWORD//@/%40}@git.d-popov.com/popov/next-cart-app.git /tmp/clone || exit 1
|
||||
GIT_COMMIT_ID=$(git -C /tmp/clone/next-cart-app rev-parse HEAD)
|
||||
LAST_COMMIT_MESSAGE=$(git log -1 --pretty=%B)
|
||||
echo "Current Git Commit: $LAST_COMMIT_MESSAGE: $GIT_COMMIT_ID"
|
||||
export GIT_COMMIT_ID
|
||||
|
||||
# Use rsync for synchronizing files, ensuring deletion of files not in source
|
||||
rsync -av --delete /tmp/clone/next-cart-app/ /app/ || echo "Rsync failed: Issue synchronizing files"
|
||||
rsync -av /tmp/clone/next-cart-app/.env* /app/ || echo "Rsync failed: Issue copying .env files"
|
||||
rsync -av /tmp/clone/next-cart-app/_deploy/entrypoint.sh /app/entrypoint.sh || echo "Rsync failed: Issue copying entrypoint.sh"
|
||||
chmod +x /app/entrypoint.sh
|
||||
# Consider uncommenting the next line to clean up after successful copy
|
||||
rm -rf /tmp/clone
|
||||
|
||||
cd /app
|
||||
echo "Installing packages in /app"
|
||||
npm install --no-audit --no-fund --no-optional --omit=optional
|
||||
yes | npx prisma generate
|
||||
#npx prisma migrate deploy
|
||||
echo "Done cloning. Current Git Commit ID: $GIT_COMMIT_ID"
|
||||
# prod script
|
||||
# npx next build
|
||||
# npx next start
|
||||
fi
|
||||
|
||||
echo "Running the main process"
|
||||
exec "$@"
|
40
_deploy/prod.Dockerfile
Normal file
40
_deploy/prod.Dockerfile
Normal file
@ -0,0 +1,40 @@
|
||||
# Dockerfile in _deploy subfolder
|
||||
|
||||
FROM node:current-alpine
|
||||
|
||||
# Set environment variables for Node.js
|
||||
ENV NODE_ENV=production
|
||||
|
||||
# Create and set the working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Install system dependencies required for building certain npm packages
|
||||
# Install git if your npm dependencies require it
|
||||
RUN apk --no-cache add git
|
||||
|
||||
# Copy package.json and package-lock.json (or yarn.lock) first to leverage Docker cache
|
||||
COPY package*.json ./
|
||||
|
||||
# Install dependencies, including Prisma if used in your project
|
||||
RUN npm install --omit=dev
|
||||
RUN npm install -g dotenv-cli
|
||||
|
||||
# Copy the rest of your app's source code from the project root to the container
|
||||
COPY . .
|
||||
|
||||
# Run Prisma generate (if needed)
|
||||
RUN npx prisma generate
|
||||
|
||||
# Copy the entrypoint script and give it execute permissions
|
||||
COPY _deploy/entrypoint.sh /usr/local/bin/
|
||||
COPY _deploy/entrypoint.sh ./
|
||||
RUN chmod +x /usr/local/bin/entrypoint.sh
|
||||
|
||||
# Expose a port (e.g., 3000) to access the app
|
||||
EXPOSE 3000
|
||||
|
||||
# Use the entrypoint script as the entrypoint
|
||||
ENTRYPOINT ["entrypoint.sh"]
|
||||
|
||||
# Start the Next.js app
|
||||
CMD ["npm", "start"]
|
65
_deploy/sample.docker-compose.yml
Normal file
65
_deploy/sample.docker-compose.yml
Normal file
@ -0,0 +1,65 @@
|
||||
version: "3.1"
|
||||
#name: gw02-mysql
|
||||
services:
|
||||
db:
|
||||
image: mariadb
|
||||
hostname: mariadb
|
||||
restart: always
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: Kc8P4h573W67Dd
|
||||
MYSQL_USER: cart # GRANT ALL PRIVILEGES ON database.* TO 'user'@'%' IDENTIFIED BY 'password';
|
||||
MYSQL_PASSWORD: cartpw2024
|
||||
MYSQL_DATABASE: cart # This will create a database named 'cart'
|
||||
stdin_open: true
|
||||
tty: true
|
||||
ports:
|
||||
- 3307:3306
|
||||
volumes:
|
||||
- /mnt/data/apps/docker_volumes/cart/database:/var/lib/mysql
|
||||
# command: >
|
||||
# sh -c '
|
||||
# export MYSQL_ROOT_PASSWORD=$$(openssl rand -base64 12);
|
||||
# echo "Generated MariaDB root password: $$MYSQL_ROOT_PASSWORD";
|
||||
# docker-entrypoint.sh mysqld
|
||||
# '
|
||||
adminer:
|
||||
image: adminer
|
||||
restart: always
|
||||
environment:
|
||||
- PHP_INI_UPLOAD_MAX_FILESIZE=500M
|
||||
- PHP_INI_POST_MAX_SIZE=500M
|
||||
ports:
|
||||
- 8083:8080
|
||||
|
||||
# THE APP
|
||||
nextjs-app:
|
||||
image: sachinvashist/nextjs-docker
|
||||
ports:
|
||||
- "8005:8005"
|
||||
volumes:
|
||||
- /mnt/data/apps/docker_volumes/cart/app:/app
|
||||
environment:
|
||||
- NODE_ENV=demo
|
||||
- DATABASE_URL=mysql://cart:cartpw2024@mariadb:3306/cart
|
||||
#! entrypoint: ["/bin/sh", "/entrypoint.sh"]
|
||||
#run: npm install && npx prisma generate && npm run test;
|
||||
# command: "npx prisma migrate deploy && npx prisma migrate deploy && npm run build && npm run start"
|
||||
# command: "npx prisma migrate resolve --applied 20231227185411_remove_email_unique_constraint && npx prisma migrate deploy && npx prisma migrate deploy && npm run build && npm run start"
|
||||
#command: /bin/sh -c "npm install && npx prisma generate && npm run test" # Install dependencies and start the app
|
||||
command: "npm run test"
|
||||
# command: >
|
||||
# /bin/sh -c "
|
||||
# apt-get update && apt-get install -y git || exit 1;
|
||||
# if [ ! -d '/app/.git' ]; then
|
||||
# echo 'Cloning stable branch from git.d-popov.com...';
|
||||
# git clone -b stable https://git.d-popov.com/repository.git /app || exit 1;
|
||||
# fi;
|
||||
# cd /app;
|
||||
# npm install && npx prisma migrate deploy && npm run build && npm run prod
|
||||
# "
|
||||
tty: true
|
||||
stdin_open: true
|
||||
# depends_on:
|
||||
# - mariadb
|
||||
|
||||
|
41
_deploy/setup-mariadb.sh
Normal file
41
_deploy/setup-mariadb.sh
Normal file
@ -0,0 +1,41 @@
|
||||
#!/bin/sh
|
||||
# Replace mariadb_root_password, mydb, myuser, and mypassword with your desired root password, MariaDB username, and password.
|
||||
|
||||
# Update APK repositories
|
||||
apk update
|
||||
|
||||
# Install MariaDB
|
||||
apk add mariadb mariadb-client
|
||||
|
||||
# Initialize the database
|
||||
mysql_install_db --user=mysql --ldata=/var/lib/mysql
|
||||
|
||||
# Start MariaDB
|
||||
rc-service mariadb start
|
||||
|
||||
# Secure the MariaDB installation (optional but recommended)
|
||||
mysql_secure_installation <<EOF
|
||||
|
||||
y # Set root password? [Y/n]
|
||||
9F2*M5*43s4& # New password
|
||||
9F2*M5*43s4& # Repeat password
|
||||
y # Remove anonymous users? [Y/n]
|
||||
y # Disallow root login remotely? [Y/n]
|
||||
y # Remove test database and access to it? [Y/n]
|
||||
y # Reload privilege tables now? [Y/n]
|
||||
EOF
|
||||
|
||||
# Create a new user and database
|
||||
mysql -u root -p9F2*M5*43s4& <<EOF
|
||||
CREATE USER 'cart'@'%' IDENTIFIED BY 'o74x642Rc8%6';
|
||||
CREATE DATABASE cart;
|
||||
GRANT ALL PRIVILEGES ON cart.* TO 'cart'@'%';
|
||||
FLUSH PRIVILEGES;
|
||||
EOF
|
||||
|
||||
# Allow remote connections (optional)
|
||||
echo "[mysqld]" >> /etc/my.cnf
|
||||
echo "bind-address = 0.0.0.0" >> /etc/my.cnf
|
||||
|
||||
# Restart MariaDB to apply changes
|
||||
rc-service mariadb restart
|
27
_deploy/setup-postgres.sh
Normal file
27
_deploy/setup-postgres.sh
Normal file
@ -0,0 +1,27 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Update APK repositories
|
||||
apk update
|
||||
|
||||
# Install PostgreSQL
|
||||
apk add postgresql postgresql-client
|
||||
|
||||
# Create a new database directory
|
||||
mkdir -p /var/lib/postgresql/data
|
||||
|
||||
# Initialize the database
|
||||
su - postgres -c "initdb /var/lib/postgresql/data"
|
||||
|
||||
# Start PostgreSQL
|
||||
su - postgres -c "pg_ctl start -D /var/lib/postgresql/data -l logfile"
|
||||
|
||||
# Create a new user and database
|
||||
su - postgres -c "psql -c \"CREATE USER myuser WITH PASSWORD 'mypassword';\""
|
||||
su - postgres -c "psql -c \"CREATE DATABASE mydb OWNER myuser;\""
|
||||
|
||||
# Enable remote connections (optional)
|
||||
echo "host all all 0.0.0.0/0 md5" >> /var/lib/postgresql/data/pg_hba.conf
|
||||
echo "listen_addresses='*'" >> /var/lib/postgresql/data/postgresql.conf
|
||||
|
||||
# Restart PostgreSQL to apply changes
|
||||
su - postgres -c "pg_ctl restart -D /var/lib/postgresql/data"
|
64
_deploy/terraform.tf
Normal file
64
_deploy/terraform.tf
Normal file
@ -0,0 +1,64 @@
|
||||
# Virtual Machines BS Series B2s EU West 736.9334 0.0000 736.9334 0.0449 $33,11
|
||||
# Virtual Network IP Addresses Standard IPv4 Static Public IP 2,217.0000 0.0000 2,217.0000 0.0047 $10,38
|
||||
|
||||
provider "azurerm" {
|
||||
features {}
|
||||
}
|
||||
|
||||
resource "azurerm_resource_group" "example" {
|
||||
name = "example-resources"
|
||||
location = "East US"
|
||||
}
|
||||
|
||||
resource "azurerm_virtual_network" "example" {
|
||||
name = "example-network"
|
||||
address_space = ["10.0.0.0/16"]
|
||||
location = azurerm_resource_group.example.location
|
||||
resource_group_name = azurerm_resource_group.example.name
|
||||
}
|
||||
|
||||
resource "azurerm_subnet" "example" {
|
||||
name = "example-subnet"
|
||||
resource_group_name = azurerm_resource_group.example.name
|
||||
virtual_network_name = azurerm_virtual_network.example.name
|
||||
address_prefixes = ["10.0.1.0/24"]
|
||||
}
|
||||
|
||||
resource "azurerm_network_interface" "example" {
|
||||
name = "example-nic"
|
||||
location = azurerm_resource_group.example.location
|
||||
resource_group_name = azurerm_resource_group.example.name
|
||||
|
||||
ip_configuration {
|
||||
name = "internal"
|
||||
subnet_id = azurerm_subnet.example.id
|
||||
private_ip_address_allocation = "Dynamic"
|
||||
}
|
||||
}
|
||||
|
||||
resource "azurerm_linux_virtual_machine" "example" {
|
||||
name = "example-vm"
|
||||
location = azurerm_resource_group.example.location
|
||||
resource_group_name = azurerm_resource_group.example.name
|
||||
network_interface_ids = [
|
||||
azurerm_network_interface.example.id,
|
||||
]
|
||||
|
||||
size = "Standard_DS2_v2"
|
||||
admin_username = "adminuser"
|
||||
admin_password = "Password1234!"
|
||||
disable_password_authentication = false
|
||||
computer_name = "hostname"
|
||||
|
||||
os_disk {
|
||||
caching = "ReadWrite"
|
||||
storage_account_type = "Premium_LRS"
|
||||
}
|
||||
|
||||
source_image_reference {
|
||||
publisher = "Canonical"
|
||||
offer = "UbuntuServer"
|
||||
sku = "18.04-LTS"
|
||||
version = "latest"
|
||||
}
|
||||
}
|
13
_deploy/test.11.yml
Normal file
13
_deploy/test.11.yml
Normal file
@ -0,0 +1,13 @@
|
||||
version: "3"
|
||||
|
||||
services:
|
||||
nextjs-app:
|
||||
image: node:20.11.0-alpine
|
||||
ports:
|
||||
- "5002:3000"
|
||||
working_dir: /app
|
||||
volumes:
|
||||
- /mnt/storage/DEV/workspace/repos/git.d-popov.com/next-cart-app/next-cart-app:/app
|
||||
environment:
|
||||
- NODE_ENV=test
|
||||
command: /bin/sh -c "npm install && npx prisma generate && npm run test; tail -f /dev/null" # Install dependencies and start the app
|
54
_deploy/testBuild.Dockerfile
Normal file
54
_deploy/testBuild.Dockerfile
Normal file
@ -0,0 +1,54 @@
|
||||
# Use a specific version of node to ensure consistent builds
|
||||
FROM node:current-alpine AS builder
|
||||
|
||||
# Set environment variables for Node.js
|
||||
ENV NODE_ENV=production
|
||||
|
||||
# Create and set the working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Install system dependencies required for building certain npm packages
|
||||
# Install git if your npm dependencies require it
|
||||
RUN apk --no-cache add git
|
||||
|
||||
# Copy package.json and package-lock.json (or yarn.lock) first to leverage Docker cache
|
||||
COPY package*.json ./
|
||||
|
||||
# Optionally, if you're using Prisma, copy the Prisma schema file
|
||||
# This is necessary for the `prisma generate` command
|
||||
COPY prisma ./prisma/
|
||||
|
||||
# Install dependencies, including Prisma if used in your project
|
||||
RUN npm install --omit=dev
|
||||
|
||||
# Install global packages if necessary
|
||||
RUN npm install -g dotenv-cli
|
||||
|
||||
# Build stage for the actual source code
|
||||
FROM node:current-alpine AS app
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy installed node_modules from builder stage
|
||||
COPY --from=builder /app/node_modules ./node_modules
|
||||
|
||||
# Copy the rest of your app's source code from the project root to the container
|
||||
COPY . .
|
||||
|
||||
# Copy over any generated files from the builder stage if necessary
|
||||
# For example, the prisma client if you're using Prisma
|
||||
COPY --from=builder /app/node_modules/.prisma/client /app/node_modules/.prisma/client
|
||||
|
||||
# Copy the entrypoint script and give it execute permissions
|
||||
COPY _deploy/entrypoint.sh /usr/local/bin/
|
||||
COPY _deploy/entrypoint.sh ./
|
||||
RUN chmod +x /usr/local/bin/entrypoint.sh
|
||||
|
||||
# Expose a port (e.g., 3000) to access the app
|
||||
EXPOSE 3000
|
||||
|
||||
# Use the entrypoint script as the entrypoint
|
||||
ENTRYPOINT ["entrypoint.sh"]
|
||||
|
||||
# Start the Next.js app
|
||||
CMD ["npm", "start"]
|
Reference in New Issue
Block a user