Thursday, April 30, 2020

Docker desktop tutorial

From the docker desktop tutorial, this is what happening if trying to run IIS in container with windows home.



Obviously, IIS goes to premium.




apt-get update

It's to check the package need to update.

And, it's base on the list in

/etc/apt/source.list

When there are more sources, they can also be in the directory

/etc/apt/source.list.d/

Wednesday, April 29, 2020

upgrade Ubuntu from wsl to wsl2


PS C:\Users\alex> wsl -l -v NAME STATE VERSION
* Ubuntu Running 1
docker-desktop-data Running 2
docker-desktop Running 2
Ubuntu-20.04 Stopped 2
PS C:\Users\alex>
wsl --set-version Ubuntu 2Conversion in progress, this may take a few minutes...
For information on key differences with WSL 2 please visit https://aka.ms/wsl2
Conversion complete.
PS C:\Users\alex>
wsl -l -v NAME STATE VERSION
* Ubuntu Stopped 2
docker-desktop-data Running 2
docker-desktop Running 2
Ubuntu-20.04 Stopped 2
PS C:\Users\alex>



Tuesday, April 28, 2020

kubectl postgres psql

Another issue:
d:\tmp>kubectl run postgres-postgresql-client --rm --tty -i --restart='Never' --names
pace default --image docker.io/postgres:10.6 --env="PGPASSWORD=$POSTGRES_PASSWORD" --
command -- psql --host postgres-postgresql -U postgres -d postgres -p 5432
error: invalid restart policy: 'Never'
See 'kubectl run -h' for help and examples


use helm to install postgres

d:\tmp>helm install postgres --set image.repository=postgres --set image.tag=10.
6 --set postgresqlDataDir=/data/pgdata --set persistence.mountPath=/data/ stable
/postgresql
WARNING: This chart is deprecated
NAME: postgres
LAST DEPLOYED: Wed Apr 29 10:16:52 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
This Helm chart is deprecated

Given the `stable` deprecation timeline (https://github.com/helm/charts#deprecat
ion-timeline), the Bitnami maintained Helm chart is now located at bitnami/chart
s (https://github.com/bitnami/charts/).

The Bitnami repository is already included in the Hubs and we will continue prov
iding the same cadence of updates, support, etc that we've been keeping here the
se years. Installation instructions are very similar, just adding the _bitnami_
repo and using it during the installation (`bitnami/` instead of `stable/
`)

```bash
$ helm repo add bitnami https://charts.bitnami.com/bitnami
$ helm install my-release bitnami/ # Helm 3
$ helm install --name my-release bitnami/ # Helm 2
```

To update an exisiting _stable_ deployment with a chart hosted in the bitnami re
pository you can execute

```bash
$ helm repo add bitnami https://charts.bitnami.com/bitnami
$ helm upgrade my-release bitnami/
```

Issues and PRs related to the chart itself will be redirected to `bitnami/charts
` GitHub repository. In the same way, we'll be happy to answer questions related
to this migration process in this issue (https://github.com/helm/charts/issues/
20969) created as a common place for discussion.

** Please be patient while the chart is being deployed **

PostgreSQL can be accessed via port 5432 on the following DNS name from within y
our cluster:

postgres-postgresql.default.svc.cluster.local - Read/Write connection

To get the password for "postgres" run:

export POSTGRES_PASSWORD=$(kubectl get secret --namespace default postgres-p
ostgresql -o jsonpath="{.data.postgresql-password}" | base64 --decode)

To connect to your database run the following command:

kubectl run postgres-postgresql-client --rm --tty -i --restart='Never' --nam
espace default --image docker.io/postgres:10.6 --env="PGPASSWORD=$POSTGRES_PASSW
ORD" --command -- psql --host postgres-postgresql -U postgres -d postgres -p 543
2



To connect to your database from outside the cluster execute the following comma
nds:

kubectl port-forward --namespace default svc/postgres-postgresql 5432:5432 &
PGPASSWORD="$POSTGRES_PASSWORD" psql --host 127.0.0.1 -U postgres -d postgre
s -p 5432

d:\tmp>kubectl get ns
NAME STATUS AGE
default Active 22h
docker Active 22h
kube-node-lease Active 22h
kube-public Active 22h
kube-system Active 22h

d:\tmp>kubectl get pods
NAME READY STATUS RESTARTS AGE
postgres-postgresql-0 1/1 Running 0 6m43s

To see mode detail :

d:\tmp>kubectl describe pods postgres-postgresql-0
Name: postgres-postgresql-0
Namespace: default
Priority: 0
...




helm repo update



d:\tmp>helm repo update
Error: no repositories found. You must add one before updating

What is helm repo exactly?

d:\tmp>helm repo list
Error: no repositories to show

OK. Just a repository. Let's add it.

d:\tmp>helm repo add stable https://kubernetes-charts.storage.googleapis.com/
"stable" has been added to your repositories

Update again.

d:\tmp>helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "stable" chart repository
Update Complete. ⎈ Happy Helming!⎈

Happy Helming

Monday, April 27, 2020

docker cheat sheet

Check current version
docker --version

Pull from image and run
docker run hello-world

Download from image
docker image ls
   
List running containers
docker container ls
docker ps 
 
List all containers
docker container ls -all
docker ps -a
Stop a container
docker container stop [container name]

Remove container
docker container rm [container name]

Docker

Looking at the installation script.
What is it in each line?


d:\dvp>docker run --detach --publish 80:80 --name webserver nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
54fec2fa59d0: Pull complete
4ede6f09aefe: Pull complete
f9dc69acb465: Pull complete
Digest: sha256:86ae264c3f4acb99b2dee4d0098c40cb8c46dcf9e1148f05d3a51c4df6758c12
Status: Downloaded newer image for nginx:latest
dd95cada14d2df693d80030e68a644d3f7f7633d8c79e93fa2eb46c0a799ad2a

Saturday, April 25, 2020

pipenv cheatsheet

Install virtual environment in the project folder (for windows)
set PIPENV_VENV_INT_PROEJCT="enabled"
pipenv install

Enter virtual environment :
pipenv shell

To quit virtual environment :
exit

Remove virtual environment
pipenv --rm

Friday, April 24, 2020

Database schema from postgres

Use pgModeler to connect postgres.

Then Import > Connection [choose local db loclhost 5432] > Database [pick one]

You see all tables.


Then click "Export".



Export as svg format.
When you have a lot of tables, you can't see this svg in whole.
Let's embed into html
<html> <html> <head> <title>Schema</title> </head> <body> <img src="./schema.svg" style="height:1000px;width:1900px"> </body> </html>
Then, open this html file to browser.




You can scroll up/down and left/right to see all tables.


Thursday, April 23, 2020

Migrate SQLite to Postgres

Dump the existing data
python manage.py dumpdata > datadump.json

When postgres connected, then
python manage.py migrate --run-syncdb

Remove contentype data
python manage.py shell

>>> from django.contrib.contenttypes.models import ContentType
>>> ContentType.objects.all().delete()
>>> quit()

Load json data
python manage.py loaddata datadump.json

Wednesday, April 22, 2020

notepad++ with bigger toolbar icon

Right click notepad++.exe, then select "properties".

In the dialog, click the button "Change high DPI settings".




sqlite cheat sheet

List all tables
.table

Show a table schema
.schema [app name]_[model name] --indent

Leave sql console
.exit

Dump data
.output [project].sql
.dump
.exit

Tuesday, April 21, 2020

Check Kubernetes yaml configuration


kubectl get pod [podname] --output=yaml -n [namespace]


Sunday, April 19, 2020

React.StrictMode

What is React.StrictMode for?


That cause my AppReducer run twice.

As github useReducer dispatch calls reduce twice #16295, I removed it.

Then my problem solved.

Thursday, April 09, 2020

Django Create project, app



Create a project
django-admin startproject myproject
 
Create virtual environment
cd myproject
py -m venv env
.\env\Scripts\activate

Install django 
pip install django

Start up an app

python manage.py startapp book

Add schema to models.py
Modify settings.py under project
Add "book" to INSTALLED_APPS

Apply model schema
python manage.py makemigrations
python manage.py migrate

Register models in admin.py
from .models import Book
admin.site.register(Book)

python manage.py runserver

Tuesday, April 07, 2020

QR Code Difference

"hello world" from python pyqrcode  





"hello world" from qrious.js


Django in Visual Studio Code

Virtual environment:  
    Set up python virtual environment.

VSCode : 

1. In the view > Command Pallete, enter > Python: Select interpreter.

2. Select the one in the venv.
    Or enter python path from virtual environment.
    For example: I have env folder as virtual environment. 
    So, I select python in env\Scripts\python.exe
    

1. In the debug view (forth icon in left sidebar):
2. Create a launch json file.
3. Configure(Or click "Add Configuration..." on the bottom right)
    Select Python
    Then django

    In launch.json,
    Remove "--noreload"

    Both  settings.json and launch.json are in the project .vscode folder.

To start django:
1. Click the top left green triangle to start django.


Errors: 

1. If you have this error :

    Exception has occurred: ImportErr
    Couldn't import Django. 
    Are you sure it's installed and available on your PYTHONPATH environment variable?     ....

    then do

    pip install django.


2. How to set the port number?


The correct way to change port number is
  "configurations": [
    {
      "name""Python: Django",
      "type""python",
      "request""launch",
      "program""${workspaceFolder}\\manage.py",
      "args": [
        "runserver",
        "127.0.0.1:7000"
      ],
      "django"true,
    }
  ]


3. You may still trouble to start up the django, try to use the following  launch.json file:

{
    "version""0.2.0",
    "configurations": [
        {
            "name""Python: Django",
            "type""python",
            "request""launch",
            "program""${workspaceFolder}\\manage.py",
            "args": [
                "runserver",
                "0.0.0.0:8001"
            ],
            "django"true
        }
    ]
}