My Notebook

  • Databases

    Various database related notes

  • Docker

    Docker related notes

  • Git

    GIT related notes

  • SSL

    SSL related notes

Subsections of My Notebook

Subsections of Databases

Oracle

Subsections of Oracle

How to create DB

Modify following script with your user/password (database will be created with same name as username)

ALTER SESSION SET "_ORACLE_SCRIPT"=true;

CREATE USER username IDENTIFIED BY "password";
GRANT CONNECT TO username;
GRANT CONNECT, RESOURCE TO username;
GRANT CREATE SESSION TO username;
GRANT UNLIMITED TABLESPACE TO username;
GRANT SELECT ON SYS.DBA_RECYCLEBIN TO username;

QUIT

script can be run as:

sqlplus sys/sys_password@hostname:1521/ORCLCDB as SYSDBA @/oracle-init.sql;

How to drop DB

ALTER SESSION SET "_ORACLE_SCRIPT"=true;

DROP USER username CASCADE;

QUIT

script can be run as:

sqlplus sys/sys_password@hostname:1521/ORCLCDB as SYSDBA @/oracle-init.sql;

SQLServer

Subsections of SQLServer

How to create DB

Modify following script without your user/db/password

CREATE DATABASE database;
GO
USE database;
GO
CREATE LOGIN username WITH PASSWORD = 'password';
GO
CREATE USER username FOR LOGIN username;
GO

script can be run as:

/opt/mssql-tools/bin/sqlcmd -S "hostname,1433" -U SA -P SA_PASSWORD -i /sqlserver-init.sql;

Subsections of Docker

Healthcheck

Health check in docker-compose.yml is usually done as:

healthcheck:
  test: ["CMD", "curl -- fail http://localhost:8080/health"]
  interval: 10s
  timeout: 5s
  retries: 5

but when curl or wget are not available in minimalistic images the same can be achieved using following healthcheck.sh script

#!/bin/bash

exec 5<> /dev/tcp/localhost/8080
cat <&5 &
printf "GET /health HTTP/1.0\r\n\r\n" >&5

then in docker compose

volumes:
  - ./healthcheck.sh:/healthcheck.sh
healthcheck:
  test: ["CMD", "/healthcheck.sh"]
  interval: 10s
  timeout: 5s
  retries: 5

Subsections of Git

How to add commit from develop to release branch

Checkout release branch:

git checkout releases/1.2.3

Create branch from release branch:

git checkout -b feature/my-branch

Cherry-pick commit from develop (-x will add info about source commit):

git cherry-pick -x commit-hash
git push --set-upstream origin feature/my-branch

Create PR from feature branch to release branch

SSL

Subsections of SSL

Custom CA using OpenSSL

Generate a Private Key for the CA

openssl genrsa -out ca.key 2048

Create a Certificate Signing Request (CSR) for the CA

openssl req -new -x509 -days 365 -key ca.key -out ca.crt -subj "/C=CZ/ST=CZ/L=Prague/O=My CA/OU=CA/CN=My CA"

Generate a Private Key for the Server

openssl genrsa -out server.key 2048 

Create a CSR for the Server

openssl req -new -key server.key -out server.csr -subj "/C=US/ST=California/L=San Francisco/O=My Organization/OU=Server/CN=my.domain.com"

Sign the Server’s CSR with the CA

openssl ca -in server.csr -out server.crt -key ca.key -cert ca.crt -days 365

Keytool

Generate private key (will do self-signed cert as well)

keytool -genkey -alias my_alias -keyalg RSA -keystore my_keystore.jks -keysize 2048

Create CSR from keystore

keytool -certreq -alias my_alias -keyalg RSA -file my_certreq.csr -keystore my_keystore.jks

Import Certificate

cat my_cert.pem intermediate-ca.pem root-ca.pem > fullchain.pem
keytool -import -keystore my_keystore.jks -alias my_alias -file fullchain.pem 

List Certificates

keytool -list -keystore my_keystore.jks -v