mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 10:32:41 +00:00
update build script to use regions instead of prod/alt, just single build for docker, remove bun start up
This commit is contained in:
+4
-24
@@ -4,8 +4,9 @@ FROM node:18
|
|||||||
ARG GIT_COMMIT=unknown
|
ARG GIT_COMMIT=unknown
|
||||||
ENV GIT_COMMIT=$GIT_COMMIT
|
ENV GIT_COMMIT=$GIT_COMMIT
|
||||||
|
|
||||||
# Set the working directory for the build
|
# Install Nginx, Supervisor and Git (for Husky)
|
||||||
WORKDIR /build
|
RUN apt-get update && apt-get install -y nginx supervisor git && \
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Set the working directory in the container
|
# Set the working directory in the container
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
@@ -16,7 +17,7 @@ COPY package*.json ./
|
|||||||
# Install dependencies while bypassing Husky hooks
|
# Install dependencies while bypassing Husky hooks
|
||||||
ENV HUSKY=0
|
ENV HUSKY=0
|
||||||
ENV NPM_CONFIG_IGNORE_SCRIPTS=1
|
ENV NPM_CONFIG_IGNORE_SCRIPTS=1
|
||||||
RUN mkdir -p .git && npm install --include=dev
|
RUN mkdir -p .git && npm install
|
||||||
|
|
||||||
# Copy the rest of the application code
|
# Copy the rest of the application code
|
||||||
COPY . .
|
COPY . .
|
||||||
@@ -24,27 +25,6 @@ COPY . .
|
|||||||
# Build the client-side application
|
# Build the client-side application
|
||||||
RUN npm run build-prod
|
RUN npm run build-prod
|
||||||
|
|
||||||
ENV NODE_ENV=production
|
|
||||||
ARG GIT_COMMIT=unknown
|
|
||||||
ENV GIT_COMMIT=$GIT_COMMIT
|
|
||||||
|
|
||||||
# Install Nginx, Supervisor and Git (for Husky)
|
|
||||||
RUN apt-get update && apt-get install -y nginx supervisor && \
|
|
||||||
rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
# Set the working directory in the container
|
|
||||||
WORKDIR /usr/src/app
|
|
||||||
|
|
||||||
# Copy output files from builder (using the correct 'static' directory)
|
|
||||||
COPY --from=builder /build/static ./static
|
|
||||||
COPY --from=builder /build/node_modules ./node_modules
|
|
||||||
COPY --from=builder /build/package.json ./package.json
|
|
||||||
COPY --from=builder /build/bun.lock ./bun.lock
|
|
||||||
|
|
||||||
# Copy server files
|
|
||||||
COPY --from=builder /build/src ./src
|
|
||||||
|
|
||||||
|
|
||||||
# Copy Nginx configuration and ensure it's used instead of the default
|
# Copy Nginx configuration and ensure it's used instead of the default
|
||||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
RUN rm -f /etc/nginx/sites-enabled/default
|
RUN rm -f /etc/nginx/sites-enabled/default
|
||||||
|
|||||||
@@ -21,35 +21,35 @@ if [ -f .env ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Check command line argument
|
# Check command line argument
|
||||||
if [ $# -ne 1 ] || ([ "$1" != "staging" ] && [ "$1" != "prod" ] && [ "$1" != "alt" ]); then
|
if [ $# -ne 1 ] || ([ "$1" != "staging" ] && [ "$1" != "eu" ] && [ "$1" != "us" ]); then
|
||||||
echo "Error: Please specify environment (staging, prod, or alt)"
|
echo "Error: Please specify environment (staging, eu, or us)"
|
||||||
echo "Usage: $0 [staging|prod|alt]"
|
echo "Usage: $0 [staging|eu|us]"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ENV=$1
|
REGION=$1
|
||||||
VERSION_TAG="latest"
|
VERSION_TAG="latest"
|
||||||
DOCKER_REPO=""
|
DOCKER_REPO=""
|
||||||
|
|
||||||
# Set environment-specific variables
|
# Set environment-specific variables
|
||||||
if [ "$ENV" == "staging" ]; then
|
if [ "$REGION" == "staging" ]; then
|
||||||
print_header "DEPLOYING TO STAGING ENVIRONMENT"
|
print_header "DEPLOYING TO STAGING ENVIRONMENT"
|
||||||
SERVER_HOST=$SERVER_HOST_STAGING
|
SERVER_HOST=$SERVER_HOST_STAGING
|
||||||
DOCKER_REPO=$DOCKER_REPO_STAGING
|
DOCKER_REPO=$DOCKER_REPO_STAGING
|
||||||
elif [ "$ENV" == "alt" ]; then
|
elif [ "$REGION" == "us" ]; then
|
||||||
print_header "DEPLOYING TO ALT ENVIRONMENT"
|
print_header "DEPLOYING TO US ENVIRONMENT"
|
||||||
SERVER_HOST=$SERVER_HOST_ALT
|
SERVER_HOST=$SERVER_HOST_US
|
||||||
DOCKER_REPO=$DOCKER_REPO_PROD # Uses prod Docker repo for alt environment
|
DOCKER_REPO=$DOCKER_REPO_PROD # Uses prod Docker repo for alt environment
|
||||||
ENV="prod"
|
REGION="prod"
|
||||||
else
|
else
|
||||||
print_header "DEPLOYING TO PRODUCTION ENVIRONMENT"
|
print_header "DEPLOYING TO EU ENVIRONMENT"
|
||||||
SERVER_HOST=$SERVER_HOST_PROD
|
SERVER_HOST=$SERVER_HOST_EU
|
||||||
DOCKER_REPO=$DOCKER_REPO_PROD
|
DOCKER_REPO=$DOCKER_REPO_PROD
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check required environment variables
|
# Check required environment variables
|
||||||
if [ -z "$SERVER_HOST" ]; then
|
if [ -z "$SERVER_HOST" ]; then
|
||||||
echo "Error: SERVER_HOST_${ENV^^} not defined in .env file or environment"
|
echo "Error: SERVER_HOST_${REGION^^} not defined in .env file or environment"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ fi
|
|||||||
|
|
||||||
# Step 1: Build and upload Docker image to Docker Hub
|
# Step 1: Build and upload Docker image to Docker Hub
|
||||||
print_header "STEP 1: Building and uploading Docker image to Docker Hub"
|
print_header "STEP 1: Building and uploading Docker image to Docker Hub"
|
||||||
echo "Environment: ${ENV}"
|
echo "Region: ${REGION}"
|
||||||
echo "Using version tag: $VERSION_TAG"
|
echo "Using version tag: $VERSION_TAG"
|
||||||
echo "Docker repository: $DOCKER_REPO"
|
echo "Docker repository: $DOCKER_REPO"
|
||||||
|
|
||||||
@@ -122,7 +122,7 @@ echo "✅ Update script successfully copied to server."
|
|||||||
print_header "STEP 3: Executing update script on server"
|
print_header "STEP 3: Executing update script on server"
|
||||||
|
|
||||||
# Make the script executable on the remote server and execute it with the environment parameter
|
# Make the script executable on the remote server and execute it with the environment parameter
|
||||||
ssh -i $SSH_KEY $SERVER_HOST "chmod +x $REMOTE_UPDATE_SCRIPT && $REMOTE_UPDATE_SCRIPT $ENV $DOCKER_USERNAME $DOCKER_REPO"
|
ssh -i $SSH_KEY $SERVER_HOST "chmod +x $REMOTE_UPDATE_SCRIPT && $REMOTE_UPDATE_SCRIPT $REGION $DOCKER_USERNAME $DOCKER_REPO"
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "❌ Failed to execute update script on server."
|
echo "❌ Failed to execute update script on server."
|
||||||
@@ -130,6 +130,6 @@ if [ $? -ne 0 ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
print_header "DEPLOYMENT COMPLETED SUCCESSFULLY"
|
print_header "DEPLOYMENT COMPLETED SUCCESSFULLY"
|
||||||
echo "✅ New version deployed to ${ENV} environment!"
|
echo "✅ New version deployed to ${REGION} environment!"
|
||||||
echo "🌐 Check your ${ENV} server to verify the deployment."
|
echo "🌐 Check your ${REGION} server to verify the deployment."
|
||||||
echo "======================================================="
|
echo "======================================================="
|
||||||
+1
-1
@@ -14,7 +14,7 @@ stderr_logfile=/dev/stderr
|
|||||||
stderr_logfile_maxbytes=0
|
stderr_logfile_maxbytes=0
|
||||||
|
|
||||||
[program:node]
|
[program:node]
|
||||||
command=bun run start:server
|
command=npm run start:server
|
||||||
directory=/usr/src/app
|
directory=/usr/src/app
|
||||||
autostart=true
|
autostart=true
|
||||||
autorestart=true
|
autorestart=true
|
||||||
|
|||||||
@@ -5,22 +5,22 @@
|
|||||||
# Check if environment parameter is provided
|
# Check if environment parameter is provided
|
||||||
if [ $# -lt 3 ]; then
|
if [ $# -lt 3 ]; then
|
||||||
echo "Error: Required parameters missing"
|
echo "Error: Required parameters missing"
|
||||||
echo "Usage: $0 <environment> <docker_username> <docker_repo>"
|
echo "Usage: $0 <REGION> <docker_username> <docker_repo>"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Set parameters
|
# Set parameters
|
||||||
ENV=$1
|
REGION=$1
|
||||||
DOCKER_USERNAME=$2
|
DOCKER_USERNAME=$2
|
||||||
DOCKER_REPO=$3
|
DOCKER_REPO=$3
|
||||||
|
|
||||||
# Container and image configuration
|
# Container and image configuration
|
||||||
CONTAINER_NAME="openfront-${ENV}"
|
CONTAINER_NAME="openfront-${REGION}"
|
||||||
IMAGE_NAME="${DOCKER_USERNAME}/${DOCKER_REPO}"
|
IMAGE_NAME="${DOCKER_USERNAME}/${DOCKER_REPO}"
|
||||||
FULL_IMAGE_NAME="${IMAGE_NAME}:latest"
|
FULL_IMAGE_NAME="${IMAGE_NAME}:latest"
|
||||||
|
|
||||||
echo "======================================================"
|
echo "======================================================"
|
||||||
echo "🔄 UPDATING SERVER: ${ENV} ENVIRONMENT"
|
echo "🔄 UPDATING SERVER: ${REGION} ENVIRONMENT"
|
||||||
echo "======================================================"
|
echo "======================================================"
|
||||||
echo "Container name: ${CONTAINER_NAME}"
|
echo "Container name: ${CONTAINER_NAME}"
|
||||||
echo "Docker image: ${FULL_IMAGE_NAME}"
|
echo "Docker image: ${FULL_IMAGE_NAME}"
|
||||||
@@ -71,7 +71,12 @@ if [ -n "$PORT_CHECK" ]; then
|
|||||||
echo "Attempting to proceed anyway..."
|
echo "Attempting to proceed anyway..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Starting new container for ${ENV} environment..."
|
ENV="prod"
|
||||||
|
if [ "$REGION" == "staging" ]; then
|
||||||
|
ENV="staging"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Starting new container for ${REGION} environment..."
|
||||||
docker run -d -p 80:80 \
|
docker run -d -p 80:80 \
|
||||||
--restart=always \
|
--restart=always \
|
||||||
$VOLUME_MOUNTS \
|
$VOLUME_MOUNTS \
|
||||||
@@ -81,7 +86,7 @@ docker run -d -p 80:80 \
|
|||||||
$FULL_IMAGE_NAME
|
$FULL_IMAGE_NAME
|
||||||
|
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo "Update complete! New ${ENV} container is running."
|
echo "Update complete! New ${REGION} container is running."
|
||||||
|
|
||||||
# Final cleanup after successful deployment
|
# Final cleanup after successful deployment
|
||||||
echo "Performing final cleanup of unused Docker resources..."
|
echo "Performing final cleanup of unused Docker resources..."
|
||||||
|
|||||||
Reference in New Issue
Block a user