diff --git a/.gitea/workflows/deploy-to-s3.yml b/.gitea/workflows/deploy-to-s3.yml index 5e2b169..8141530 100644 --- a/.gitea/workflows/deploy-to-s3.yml +++ b/.gitea/workflows/deploy-to-s3.yml @@ -3,7 +3,7 @@ name: Deploy to S3 on: push: branches: - - main + - dev_main jobs: deploy: @@ -24,7 +24,7 @@ jobs: run: | apt-get update -y apt-get install -y zip - zip -r utopia-ai-hr-ats-portal.zip . \ + zip -r utopia-ai-hr-ats-portal-dev.zip . \ -x ".git/*" \ -x ".gitea/*" \ -x ".gitignore/*" \ @@ -46,7 +46,7 @@ jobs: AWS_DEFAULT_REGION: us-east-1 run: | echo "Uploading repo contents to S3..." - aws s3 cp utopia-ai-hr-ats-portal.zip s3://utopia-ai-s3-repo-bucket/utopia-ai-hr-ats-portal.zip + aws s3 cp utopia-ai-hr-ats-portal-dev.zip s3://utopia-ai-s3-bucket/utopia-ai-hr-ats-portal-dev.zip diff --git a/appspec.yml b/appspec.yml new file mode 100644 index 0000000..5232b43 --- /dev/null +++ b/appspec.yml @@ -0,0 +1,12 @@ +version: 0.0 +os: linux +files: + - source: / + destination: /opt/codedeploy-extracted-utopia-ai-hr-ats-portal-dev + file_exists_behavior: OVERWRITE + +hooks: + AfterInstall: + - location: deploy_utopia-ai-hr-ats-portal-dev.sh + timeout: 600 + runas: root \ No newline at end of file diff --git a/deploy_utopia-ai-hr-ats-portal-dev.sh b/deploy_utopia-ai-hr-ats-portal-dev.sh new file mode 100644 index 0000000..c0a19be --- /dev/null +++ b/deploy_utopia-ai-hr-ats-portal-dev.sh @@ -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 =====" \ No newline at end of file