|
|
|
|
@ -0,0 +1,89 @@
|
|
|
|
|
#!/bin/bash
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
# Where CodeDeploy extracted the zip package
|
|
|
|
|
EXTRACT_DIR="/opt/codedeploy-extracted-utopia-ai-hr-ats-portal-dev"
|
|
|
|
|
|
|
|
|
|
# Dynamically set the true destination path based on the CodeDeploy group name
|
|
|
|
|
if [ -z "${DEPLOYMENT_GROUP_NAME}" ]; then
|
|
|
|
|
TARGET_DIR="utopia-ai-hr-ats-portal-dev-deployment-group"
|
|
|
|
|
else
|
|
|
|
|
TARGET_DIR="${DEPLOYMENT_GROUP_NAME}"
|
|
|
|
|
fi
|
|
|
|
|
FINAL_DIR="/home/ec2-user/${TARGET_DIR}"
|
|
|
|
|
|
|
|
|
|
echo "===== Moving files safely to ${FINAL_DIR} ====="
|
|
|
|
|
# Ensure the final folder exists (won't alter it if it does)
|
|
|
|
|
mkdir -p "${FINAL_DIR}"
|
|
|
|
|
|
|
|
|
|
# Copy everything from the extraction directory to your app folder
|
|
|
|
|
# This will overwrite code files, but leave your untracked .env safe and untouched!
|
|
|
|
|
cp -r "${EXTRACT_DIR}/." "${FINAL_DIR}/"
|
|
|
|
|
|
|
|
|
|
# Change into the actual app directory
|
|
|
|
|
cd "${FINAL_DIR}"
|
|
|
|
|
|
|
|
|
|
# Fix ownership so ec2-user owns the codebase
|
|
|
|
|
chown -R ec2-user:ec2-user "${FINAL_DIR}"
|
|
|
|
|
|
|
|
|
|
echo "--------- Checking/Installing Docker ---------"
|
|
|
|
|
if ! command -v docker &> /dev/null; then
|
|
|
|
|
echo "Installing Docker..."
|
|
|
|
|
dnf install docker -y
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
systemctl start docker
|
|
|
|
|
systemctl enable docker
|
|
|
|
|
usermod -aG docker ec2-user
|
|
|
|
|
|
|
|
|
|
echo "Docker: $(docker --version)"
|
|
|
|
|
|
|
|
|
|
echo "--------- Installing Latest Docker Compose ---------"
|
|
|
|
|
mkdir -p /usr/libexec/docker/cli-plugins
|
|
|
|
|
curl -SL "https://github.com/docker/compose/releases/latest/download/docker-compose-linux-$(uname -m)" \
|
|
|
|
|
-o /usr/libexec/docker/cli-plugins/docker-compose
|
|
|
|
|
chmod +x /usr/libexec/docker/cli-plugins/docker-compose
|
|
|
|
|
echo "Docker Compose: $(docker compose version)"
|
|
|
|
|
|
|
|
|
|
echo "--------- Installing Latest Docker Buildx ---------"
|
|
|
|
|
ARCH=$(uname -m)
|
|
|
|
|
if [ "$ARCH" = "x86_64" ]; then
|
|
|
|
|
BUILDX_ARCH="amd64"
|
|
|
|
|
elif [ "$ARCH" = "aarch64" ]; then
|
|
|
|
|
BUILDX_ARCH="arm64"
|
|
|
|
|
else
|
|
|
|
|
BUILDX_ARCH="$ARCH"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Fetch latest release tag (e.g. v0.21.1)
|
|
|
|
|
BUILDX_TAG=$(curl -s https://api.github.com/repos/docker/buildx/releases/latest | grep '"tag_name"' | cut -d'"' -f4)
|
|
|
|
|
|
|
|
|
|
echo "Downloading Buildx version ${BUILDX_TAG} for ${BUILDX_ARCH}..."
|
|
|
|
|
|
|
|
|
|
# Remove any existing broken binary before downloading
|
|
|
|
|
rm -f /usr/libexec/docker/cli-plugins/docker-buildx
|
|
|
|
|
|
|
|
|
|
curl -SL "https://github.com/docker/buildx/releases/download/${BUILDX_TAG}/buildx-${BUILDX_TAG}.linux-${BUILDX_ARCH}" \
|
|
|
|
|
-o /usr/libexec/docker/cli-plugins/docker-buildx
|
|
|
|
|
chmod +x /usr/libexec/docker/cli-plugins/docker-buildx
|
|
|
|
|
echo "Docker Buildx: $(docker buildx version)"
|
|
|
|
|
|
|
|
|
|
if [ ! -f "docker-compose.yml" ]; then
|
|
|
|
|
echo "ERROR: docker-compose.yml not found in ${FINAL_DIR}"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "--------- Stopping existing containers ---------"
|
|
|
|
|
docker compose down --remove-orphans || true
|
|
|
|
|
|
|
|
|
|
echo "--------- Building and starting containers ---------"
|
|
|
|
|
docker compose --env-file ./backend/.env build --no-cache
|
|
|
|
|
docker compose --env-file ./backend/.env up -d
|
|
|
|
|
|
|
|
|
|
echo "--------- Running containers ---------"
|
|
|
|
|
docker ps
|
|
|
|
|
|
|
|
|
|
# Optional: Clean up extraction directory to keep disk space clean
|
|
|
|
|
rm -rf "${EXTRACT_DIR:?}/*"
|
|
|
|
|
|
|
|
|
|
echo "===== Deployment completed successfully ====="
|