Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Docker Support and CI Pipeline for Backend #27

Merged
merged 9 commits into from
Nov 26, 2024
Merged

Conversation

AhmedFatthy1040
Copy link
Owner

Add Docker Support and CI Pipeline for Backend

Description

This PR introduces two key enhancements:

  1. Docker Integration: Adds configuration files and scripts to containerize the backend application and manage it using Docker Compose.
  2. CI Pipeline: Sets up a GitHub Actions CI pipeline to automate the build process for the backend.

Changes

Docker Integration

  • Added Docker Compose configuration:
    api:
        build:
          context: .
          dockerfile: Dockerfile.api
        container_name: hias-api
        environment:
          POSTGRES_USER: hias-user
          POSTGRES_PASSWORD: 123456
          POSTGRES_DB: hias
          POSTGRES_HOST: postgres
          NODE_ENV: production
        ports:
          - "5000:5000"
        depends_on:
          - postgres
        command: ["npm", "run", "start"]  

Created Dockerfile.api:

  • Added a Dockerfile to containerize the backend API.
  • Key Features:
    • Base Image: Node.js (version 18).
    • Working Directory: /app.
    • Build Steps:
      • Copies the package.json and package-lock.json.
      • Installs dependencies using npm install.
      • Copies all application files into the container.
      • Runs the backend using npm run start.

Updated package.json:

  • Added a clean script to simplify build cleanup:
    "clean": "rm -rf dist"

Updated db.ts:

  • Enhanced database configuration to support Docker deployment:
    host: process.env.DB_HOST, // Container name if using Docker

Added CI Pipeline for Backend:

  • Implemented a GitHub Actions workflow to automate backend builds.
  • Workflow Features:
    • Triggered on push and pull_request events to the main branch.
    • Automates the build process by compiling TypeScript to JavaScript.

Checklist

  • Updated db.ts with Docker compatibility.
  • Added Dockerfile.api for API containerization.
  • Enhanced package.json with a clean script.
  • Added a CI workflow for backend builds.

Next Steps

  • Verify the Dockerized API functionality in production-like environments.
  • Continuously monitor the CI pipeline for build integrity.

- Added a GitHub Actions workflow to build the backend.
- The pipeline runs on push and pull requests for the main and develop branches.
- It includes steps for installing dependencies, and building the backend.
- Added a GitHub Actions workflow to build the backend.
- The pipeline runs on push and pull requests for the main branch.
- It includes steps for installing dependencies, and building the backend.
- Rename tables: annotation → Annotations, image → Images, category → Categories, user → Users
- Update column names to camelCase (e.g., image_id → imageId, created_at → createdAt)
- Adjust foreign key constraints to follow new naming conventions
- Added @types/pg as a dev dependency to provide TypeScript type definitions for the 'pg' module.
- This resolves the TS7016 error related to the missing declaration file for 'pg'.
- Fixed a typo in the `.github/workflows/ci.yml` file to ensure proper execution of the CI pipeline.
Copy link
Collaborator

@justFadel19 justFadel19 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@justFadel19 justFadel19 merged commit f672aaf into main Nov 26, 2024
1 check passed
@AhmedFatthy1040 AhmedFatthy1040 deleted the dockerizing-api branch November 26, 2024 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants