Difference between revisions of "Github Action using ssh"

From Logic Wiki
Jump to: navigation, search
(Created page with "Category:Github Category:ssh Category:CI/CD == Introducing github to server == First create a ssh key in the local machine (I named it as "github-deploy" when it...")
 
Line 12: Line 12:
 
Copy it to server
 
Copy it to server
 
  ssh-copy-id -i ~/.ssh/github-deploy.pub bookit
 
  ssh-copy-id -i ~/.ssh/github-deploy.pub bookit
'''Add public key to authorized_keys'''
 
 
  
 
Create a secret in Github repo and store private key in it.
 
Create a secret in Github repo and store private key in it.
Line 21: Line 19:
 
Create the key on the server and copy private key to github secrets
 
Create the key on the server and copy private key to github secrets
 
== Server Side ==
 
== Server Side ==
 +
* '''Add public key to authorized_keys'''
 
* install docker
 
* install docker
 
* install docker-compose
 
* install docker-compose

Revision as of 13:02, 5 December 2025


Introducing github to server

First create a ssh key in the local machine (I named it as "github-deploy" when it asked)

ssh-keygen -t ed25519 -C "github-deploy"

-t ed25519 : encryption algorithm

-C "github-deploy" : puts a comment in public key file

Copy it to server

ssh-copy-id -i ~/.ssh/github-deploy.pub bookit

Create a secret in Github repo and store private key in it.

OR

Create the key on the server and copy private key to github secrets

Server Side

  • Add public key to authorized_keys
  • install docker
  • install docker-compose
  • create folder for deployment

Action

services:
  rabbitmq:
    image: rabbitmq:3-management
    container_name: rabbitmq
    ports:
      - "5672:5672"
      - "15672:15672"
    environment:
      RABBITMQ_DEFAULT_USER: ${RABBITMQ_DEFAULT_USER}
      RABBITMQ_DEFAULT_PASS: ${RABBITMQ_DEFAULT_PASS}
  mongo:
    image: mongo
    restart: always
    environment:
      MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME}
      MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD}
    ports:
      - "27017:27017" 
    volumes:
      - ./data/mongo:/data/db
  postgres:
    image: postgres:18
    restart: always
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    healthcheck:
      test: ["CMD-SHELL", "pg_isready"]
      interval: 1s
      timeout: 5s
      retries: 10
    ports:
      - "5432:5432"
    volumes:
      - ./data/postgres:/var/lib/postgresql/18/main
      - ./sql/create_db.sql:/docker-entrypoint-initdb.d/create_db.sql
    networks:
      - logic_network

  redis:
    container_name: redis
    image: redis
    restart: always
    ports:
      - "6379:6379"
    volumes:
      - ./data/redis:/data/redis  
  keycloak:
    image: quay.io/keycloak/keycloak
    environment:
      KC_DB: postgres
      KC_DB_URL: jdbc:postgresql://postgres:5432/logic_keycloak
      KC_DB_USERNAME: ${POSTGRES_USER}
      KC_DB_PASSWORD: ${POSTGRES_PASSWORD}
      KEYCLOAK_ADMIN: ${KEYCLOAK_ADMIN}
      KEYCLOAK_ADMIN_PASSWORD: ${KEYCLOAK_ADMIN_PASSWORD}
      KC_HEALTH_ENABLED: true
      KC_LOG_LEVEL: info
      KC_HOSTNAME_STRICT: false
      KC_HTTP_ENABLED: true
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:7080/health/ready"]
      interval: 15s
      timeout: 2s
      retries: 15
    command: ["start-dev", "--http-port", "7080", "--https-port", "7443"]
    ports:
    - "7080:7080"
    - "7443:7443"
    networks:
      - logic_network
    depends_on:
      postgres:
        condition: service_healthy
networks:
  logic_network:
    name: logic_network
    driver: bridge