Skip to content

Update Both Dockerfile and Pipeline yaml for the railway prod #still-… #27

Update Both Dockerfile and Pipeline yaml for the railway prod #still-…

Update Both Dockerfile and Pipeline yaml for the railway prod #still-… #27

Workflow file for this run

# name: CI/CD pipeline for the eventify API
# on:
# push:
# branches:
# - master
# pull_request:
# branches:
# - master
# jobs:
# build-and-test:
# runs-on: ubuntu-latest
# steps:
# # Checkout code from the repository
# - name: Checkout code
# uses: actions/checkout@v3
# # Set up Node.js environment
# - name: Set up Node.js
# uses: actions/setup-node@v3
# with:
# node-version: '20'
# # Install dependencies
# - name: Install dependencies
# run: npm install
# # Create .env file
# - name: Create .env file
# run: |
# echo ${{ secrets.PORT }} > .env
# echo ${{ secrets.MONGO_ATLAS_URI }} >> .env
# echo ${{ secrets.MAIL_HOST }} >> .env
# echo ${{ secrets.MAIL_PORT }} >> .env
# echo ${{ secrets.MAIL_USER }} >> .env
# echo ${{ secrets.MAIL_PASSWORD }} >> .env
# echo ${{ secrets.JWT_SECRET }} >> .env
# echo ${{ secrets.JWT_REFRESH_SECRET }} >> .env
# echo ${{ secrets.JWT_EXPIRES_IN }} >> .env
# echo ${{ secrets.JWT_REFRESH_TOKEN_EXPIRES_IN }} >> .env
# echo ${{ secrets.JWT_ACCESS_EXPIRES_IN }} >> .env
# # Run tests
# - name: Run unit tests
# run: npm test
# dockerize:
# runs-on: ubuntu-latest
# needs: build-and-test
# steps:
# # Checkout code from the repository
# - name: Checkout code
# uses: actions/checkout@v3
# # Set up Docker Buildx
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v2
# # Log in to Docker Hub
# - name: Log in to Docker Hub
# uses: docker/login-action@v2
# with:
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_PASSWORD }}
# # Build And Push Docker image
# - name: Build and push Docker image
# uses: docker/build-push-action@v4
# with:
# context: .
# push: true
# tags: ${{ secrets.DOCKER_USERNAME }}/eventify-api:latest
# # Log out from Docker Hub
# - name: Log out from Docker Hub
# run: docker logout
name: CI/CD pipeline for the eventify API
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build-and-test:
runs-on: ubuntu-latest
env:
NODE_ENV: test
NODE_OPTIONS: --max-old-space-size=256
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install deps (CI)
run: npm ci
# If your unit tests need env vars, write them as KEY=VALUE lines.
# (What you had before wrote only values, which doesn't work.)
- name: Create .env for tests
run: |
{
echo "PORT=${{ secrets.PORT }}"
echo "MONGO_URI=${{ secrets.MONGO_ATLAS_URI }}"
echo "MAIL_HOST=${{ secrets.MAIL_HOST }}"
echo "MAIL_PORT=${{ secrets.MAIL_PORT }}"
echo "MAIL_USER=${{ secrets.MAIL_USER }}"
echo "MAIL_PASSWORD=${{ secrets.MAIL_PASSWORD }}"
echo "JWT_SECRET=${{ secrets.JWT_SECRET }}"
echo "JWT_REFRESH_SECRET=${{ secrets.JWT_REFRESH_SECRET }}"
echo "JWT_EXPIRES_IN=${{ secrets.JWT_EXPIRES_IN }}"
echo "JWT_REFRESH_TOKEN_EXPIRES_IN=${{ secrets.JWT_REFRESH_TOKEN_EXPIRES_IN }}"
echo "JWT_ACCESS_EXPIRES_IN=${{ secrets.JWT_ACCESS_EXPIRES_IN }}"
} > .env
- name: TypeScript build (ensure dist exists)
run: npm run build
- name: Run unit tests (reduced workers to avoid OOM)
run: npm test -- --runInBand --maxWorkers=50%
dockerize:
runs-on: ubuntu-latest
needs: build-and-test
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# Optional: Add metadata (labels, semver tags, sha)
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ secrets.DOCKER_USERNAME }}/eventify-api
tags: |
type=raw,value=latest
type=sha
- name: Build and push (prod stage)
uses: docker/build-push-action@v6
with:
context: .
push: true
target: prod # <- uses the prod stage from the Dockerfile I provided
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Logout Docker Hub
run: docker logout