diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 114e2e6d..c6f9b297 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -32,6 +32,7 @@ jobs: next_public_base_url: ${{ steps.determine.outputs.next_public_base_url }} directus_url: ${{ steps.determine.outputs.directus_url }} directus_host: ${{ steps.determine.outputs.directus_host }} + project_name: ${{ steps.determine.outputs.project_name }} is_prod: ${{ steps.determine.outputs.is_prod }} gotify_title: ${{ steps.determine.outputs.gotify_title }} gotify_priority: ${{ steps.determine.outputs.gotify_priority }} @@ -59,6 +60,7 @@ jobs: NEXT_PUBLIC_BASE_URL="https://testing.klz-cables.com" DIRECTUS_URL="https://cms-testing.klz-cables.com" DIRECTUS_HOST='`cms-testing.klz-cables.com`' + PROJECT_NAME="klz-cables-testing" IS_PROD="false" GOTIFY_TITLE="๐Ÿงช Testing-Deploy" GOTIFY_PRIORITY=4 @@ -71,6 +73,7 @@ jobs: NEXT_PUBLIC_BASE_URL="https://klz-cables.com" DIRECTUS_URL="https://cms.klz-cables.com" DIRECTUS_HOST='`cms.klz-cables.com`' + PROJECT_NAME="klz-cables-prod" IS_PROD="true" GOTIFY_TITLE="๐Ÿš€ Production-Release" GOTIFY_PRIORITY=6 @@ -82,6 +85,7 @@ jobs: NEXT_PUBLIC_BASE_URL="https://staging.klz-cables.com" DIRECTUS_URL="https://cms-staging.klz-cables.com" DIRECTUS_HOST='`cms-staging.klz-cables.com`' + PROJECT_NAME="klz-cables-staging" IS_PROD="false" GOTIFY_TITLE="๐Ÿงช Staging-Deploy (Pre-Release)" GOTIFY_PRIORITY=5 @@ -101,6 +105,7 @@ jobs: echo "next_public_base_url=$NEXT_PUBLIC_BASE_URL" >> $GITHUB_OUTPUT echo "directus_url=$DIRECTUS_URL" >> $GITHUB_OUTPUT echo "directus_host=$DIRECTUS_HOST" >> $GITHUB_OUTPUT + echo "project_name=$PROJECT_NAME" >> $GITHUB_OUTPUT echo "is_prod=$IS_PROD" >> $GITHUB_OUTPUT echo "gotify_title=$GOTIFY_TITLE" >> $GITHUB_OUTPUT echo "gotify_priority=$GOTIFY_PRIORITY" >> $GITHUB_OUTPUT @@ -166,15 +171,6 @@ jobs: run: | echo "${{ secrets.REGISTRY_PASS }}" | docker login registry.infra.mintel.me -u "${{ secrets.REGISTRY_USER }}" --password-stdin - - name: ๐Ÿ“ฆ Restore Next.js cache - uses: actions/cache@v4 - with: - path: .next/cache - key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }} - restore-keys: | - ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}- - ${{ runner.os }}-nextjs- - - name: ๐Ÿ—๏ธ Docker Image bauen & pushen env: IMAGE_TAG: ${{ needs.prepare.outputs.image_tag }} @@ -197,12 +193,6 @@ jobs: --cache-to type=registry,ref=registry.infra.mintel.me/mintel/klz-cables.com:buildcache,mode=max \ --push . - - name: ๐Ÿ“ฆ Save Next.js cache - uses: actions/cache/save@v4 - if: always() - with: - path: .next/cache - key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }} # โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ # JOB 4: Deploy via SSH @@ -228,6 +218,7 @@ jobs: MAIL_RECIPIENTS: ${{ secrets.MAIL_RECIPIENTS }} DIRECTUS_URL: ${{ needs.prepare.outputs.directus_url }} DIRECTUS_HOST: ${{ needs.prepare.outputs.directus_host }} + PROJECT_NAME: ${{ needs.prepare.outputs.project_name }} DIRECTUS_KEY: ${{ secrets.DIRECTUS_KEY }} DIRECTUS_SECRET: ${{ secrets.DIRECTUS_SECRET }} DIRECTUS_ADMIN_EMAIL: ${{ secrets.DIRECTUS_ADMIN_EMAIL }} @@ -283,16 +274,16 @@ jobs: scp -o StrictHostKeyChecking=accept-new /tmp/klz-cables.env root@alpha.mintel.me:/home/deploy/sites/klz-cables.com/$ENV_FILE scp -o StrictHostKeyChecking=accept-new docker-compose.yml root@alpha.mintel.me:/home/deploy/sites/klz-cables.com/docker-compose.yml - ssh -o StrictHostKeyChecking=accept-new root@alpha.mintel.me IMAGE_TAG="$IMAGE_TAG" ENV_FILE="$ENV_FILE" bash << 'EOF' + ssh -o StrictHostKeyChecking=accept-new root@alpha.mintel.me IMAGE_TAG="$IMAGE_TAG" ENV_FILE="$ENV_FILE" PROJECT_NAME="$PROJECT_NAME" bash << 'EOF' set -e cd /home/deploy/sites/klz-cables.com chmod 600 "$ENV_FILE" chown deploy:deploy "$ENV_FILE" echo "${{ secrets.REGISTRY_PASS }}" | docker login registry.infra.mintel.me -u "${{ secrets.REGISTRY_USER }}" --password-stdin echo "โ†’ Pulling image: $IMAGE_TAG" - docker compose --env-file "$ENV_FILE" pull + docker compose -p "$PROJECT_NAME" --env-file "$ENV_FILE" pull echo "โ†’ Starting containers..." - docker compose --env-file "$ENV_FILE" up -d + docker compose -p "$PROJECT_NAME" --env-file "$ENV_FILE" up -d --remove-orphans docker system prune -f --filter "until=168h" echo "โ†’ Waiting 15s for warmup..." sleep 15 diff --git a/Dockerfile b/Dockerfile index f9e97c45..e7b20d55 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ WORKDIR /app # Install dependencies based on the preferred package manager COPY package.json package-lock.json* ./ -RUN npm ci +RUN --mount=type=cache,target=/root/.npm npm ci # Rebuild the source code only when needed @@ -37,7 +37,7 @@ ENV DIRECTUS_URL=$DIRECTUS_URL # Validate environment variables during build RUN npx tsx scripts/validate-env.ts -RUN npm run build +RUN --mount=type=cache,target=/app/.next/cache npm run build # Production image, copy all the files and run next FROM base AS runner