mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 16:26:37 +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
|
||||
ENV GIT_COMMIT=$GIT_COMMIT
|
||||
|
||||
# Set the working directory for the build
|
||||
WORKDIR /build
|
||||
# Install Nginx, Supervisor and Git (for Husky)
|
||||
RUN apt-get update && apt-get install -y nginx supervisor git && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Set the working directory in the container
|
||||
WORKDIR /usr/src/app
|
||||
@@ -16,7 +17,7 @@ COPY package*.json ./
|
||||
# Install dependencies while bypassing Husky hooks
|
||||
ENV HUSKY=0
|
||||
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 . .
|
||||
@@ -24,27 +25,6 @@ COPY . .
|
||||
# Build the client-side application
|
||||
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.conf /etc/nginx/conf.d/default.conf
|
||||
RUN rm -f /etc/nginx/sites-enabled/default
|
||||
|
||||
@@ -21,35 +21,35 @@ if [ -f .env ]; then
|
||||
fi
|
||||
|
||||
# Check command line argument
|
||||
if [ $# -ne 1 ] || ([ "$1" != "staging" ] && [ "$1" != "prod" ] && [ "$1" != "alt" ]); then
|
||||
echo "Error: Please specify environment (staging, prod, or alt)"
|
||||
echo "Usage: $0 [staging|prod|alt]"
|
||||
if [ $# -ne 1 ] || ([ "$1" != "staging" ] && [ "$1" != "eu" ] && [ "$1" != "us" ]); then
|
||||
echo "Error: Please specify environment (staging, eu, or us)"
|
||||
echo "Usage: $0 [staging|eu|us]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ENV=$1
|
||||
REGION=$1
|
||||
VERSION_TAG="latest"
|
||||
DOCKER_REPO=""
|
||||
|
||||
# Set environment-specific variables
|
||||
if [ "$ENV" == "staging" ]; then
|
||||
if [ "$REGION" == "staging" ]; then
|
||||
print_header "DEPLOYING TO STAGING ENVIRONMENT"
|
||||
SERVER_HOST=$SERVER_HOST_STAGING
|
||||
DOCKER_REPO=$DOCKER_REPO_STAGING
|
||||
elif [ "$ENV" == "alt" ]; then
|
||||
print_header "DEPLOYING TO ALT ENVIRONMENT"
|
||||
SERVER_HOST=$SERVER_HOST_ALT
|
||||
elif [ "$REGION" == "us" ]; then
|
||||
print_header "DEPLOYING TO US ENVIRONMENT"
|
||||
SERVER_HOST=$SERVER_HOST_US
|
||||
DOCKER_REPO=$DOCKER_REPO_PROD # Uses prod Docker repo for alt environment
|
||||
ENV="prod"
|
||||
REGION="prod"
|
||||
else
|
||||
print_header "DEPLOYING TO PRODUCTION ENVIRONMENT"
|
||||
SERVER_HOST=$SERVER_HOST_PROD
|
||||
print_header "DEPLOYING TO EU ENVIRONMENT"
|
||||
SERVER_HOST=$SERVER_HOST_EU
|
||||
DOCKER_REPO=$DOCKER_REPO_PROD
|
||||
fi
|
||||
|
||||
# Check required environment variables
|
||||
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
|
||||
fi
|
||||
|
||||
@@ -67,7 +67,7 @@ fi
|
||||
|
||||
# Step 1: Build and upload 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 "Docker repository: $DOCKER_REPO"
|
||||
|
||||
@@ -122,7 +122,7 @@ echo "✅ Update script successfully copied to 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
|
||||
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
|
||||
echo "❌ Failed to execute update script on server."
|
||||
@@ -130,6 +130,6 @@ if [ $? -ne 0 ]; then
|
||||
fi
|
||||
|
||||
print_header "DEPLOYMENT COMPLETED SUCCESSFULLY"
|
||||
echo "✅ New version deployed to ${ENV} environment!"
|
||||
echo "🌐 Check your ${ENV} server to verify the deployment."
|
||||
echo "✅ New version deployed to ${REGION} environment!"
|
||||
echo "🌐 Check your ${REGION} server to verify the deployment."
|
||||
echo "======================================================="
|
||||
+1
-1
@@ -14,7 +14,7 @@ stderr_logfile=/dev/stderr
|
||||
stderr_logfile_maxbytes=0
|
||||
|
||||
[program:node]
|
||||
command=bun run start:server
|
||||
command=npm run start:server
|
||||
directory=/usr/src/app
|
||||
autostart=true
|
||||
autorestart=true
|
||||
|
||||
@@ -5,22 +5,22 @@
|
||||
# Check if environment parameter is provided
|
||||
if [ $# -lt 3 ]; then
|
||||
echo "Error: Required parameters missing"
|
||||
echo "Usage: $0 <environment> <docker_username> <docker_repo>"
|
||||
echo "Usage: $0 <REGION> <docker_username> <docker_repo>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Set parameters
|
||||
ENV=$1
|
||||
REGION=$1
|
||||
DOCKER_USERNAME=$2
|
||||
DOCKER_REPO=$3
|
||||
|
||||
# Container and image configuration
|
||||
CONTAINER_NAME="openfront-${ENV}"
|
||||
CONTAINER_NAME="openfront-${REGION}"
|
||||
IMAGE_NAME="${DOCKER_USERNAME}/${DOCKER_REPO}"
|
||||
FULL_IMAGE_NAME="${IMAGE_NAME}:latest"
|
||||
|
||||
echo "======================================================"
|
||||
echo "🔄 UPDATING SERVER: ${ENV} ENVIRONMENT"
|
||||
echo "🔄 UPDATING SERVER: ${REGION} ENVIRONMENT"
|
||||
echo "======================================================"
|
||||
echo "Container name: ${CONTAINER_NAME}"
|
||||
echo "Docker image: ${FULL_IMAGE_NAME}"
|
||||
@@ -71,7 +71,12 @@ if [ -n "$PORT_CHECK" ]; then
|
||||
echo "Attempting to proceed anyway..."
|
||||
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 \
|
||||
--restart=always \
|
||||
$VOLUME_MOUNTS \
|
||||
@@ -81,7 +86,7 @@ docker run -d -p 80:80 \
|
||||
$FULL_IMAGE_NAME
|
||||
|
||||
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
|
||||
echo "Performing final cleanup of unused Docker resources..."
|
||||
|
||||
Reference in New Issue
Block a user