1/29/2019

How to install wget in macOS?

install by brew
>ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
>brew install wget --with-libressl

install by port
> sudo port install wget


Enjoy!





1/28/2019

tar (child): xz: Cannot exec: No such file or directory on Amazon Linux

yum install -y xz

docker command summarise


stop all containers:
docker kill $(docker ps -q)

remove all containers
docker rm $(docker ps -a -q)

remove all docker images
docker rmi $(docker images -q)

access(enter) docker container
docker exec -it docker_container_name sh

Exit from docker container
>exit

Commit container and build image
docker commit container_name image_name
ex) docker commit lambdapack lambda_image
ex) docker commit lambdapack marearts/lambda_image:v1.0.0

Docker build
>docker build --tag hello:0.1 .
>docker build --tag marearts/hello:0.1 .

Docker run shell and tunnelling 
>docker run -v $(pwd):/outputs --name nickname -d docker_image tail -f /dev/null
ex)
>docker run -v $(pwd):/outputs --name lambdapackgen2 -d marearts/awspy:0.1 tail -f /dev/null

Docker run shell

> docker run -it marearts/amazon_linux_py36:v1.0.0 /bin/bash

Docker run sh file in container
>docker exec -i -t container_name /bin/bash /outputs/shfile.sh
ex)
>docker exec -i -t lambdapackgen2 /bin/bash /outputs/buildPack_py3.sh

Restart Docker container
>docker restart <container id or name>
ex)
docker restart 59



it will be updated..


1/27/2019

summarise Azure function docker image deploy



*make python virtualenv
*activate python virtualenv !!
*install azure util cli
https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-function-linux-custom-image#run-the-build-command

make project (app)
func init DocApp100 --docker

change directory
cd DocApp100

new function
func new --name MyHttpTrigger --template "HttpTrigger"

build docker image
docker build --tag marearts/image:v1 .

make new resource group
az group create --name DocGroup --location westeurope

storage account
az storage account create --name docstorage100 --location westeurope --resource-group DocGroup --sku Standard_LRS

create linux service plan
az appservice plan create --name docserviceplan --resource-group DocGroup --sku B1 --is-linux

create app and deploy
az functionapp create --name docapp100 --storage-account docstorage100 --resource-group DocGroup --plan docserviceplan --deployment-container-image-name marearts/image:v1

Configuration the function app
storageConnectionString=$(az storage account show-connection-string --resource-group DocGroup --name docstorage100 --query connectionString --output tsv)
az functionapp config appsettings set --name docapp100 --resource-group DocGroup --settings AzureWebJobsDashboard=$storageConnectionString AzureWebJobsStorage=$storageConnectionString

Test
curl https://docapp100.azurewebsites.net/api/MyHttpTrigger?name=myname


Azure function create command summarise.

reference:
https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local#v2
https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-first-function-python


create project
func init PythonAzure

create azure function
func new

Test
func host test

create resource group
az group create --name mareartstest --location westeurope

create strage account
az storage account create --name mareartsteststorage --location westeurope --resource-group mareartstest --sku Standard_LRS

create app
az functionapp create --resource-group mareartstest --os-type Linux --consumption-plan-location westeurope --runtime python --name mareartstest --storage-account mareartsteststorage

deploy
func azure functionapp publish mareartstest

1/23/2019

python "argparse" simple usage


If you use "argparse" lib, you can get the argument parameters very easily in python.
Let's look below code.

test1.py
import argparse

# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
#param add
ap.add_argument("-z", "--zip", type=int, required=True, help="input zip code")
#param add
ap.add_argument("-n", "--name", type=str, required=True, help="input your name")

#get param
args = ap.parse_args()
print(args.zip)
print(args.name)
print('---------')

#get param
args = vars(ap.parse_args())
print(args["zip"])
print(args["name"])
..

The code accepts 2 arguments those are 'zip' and 'name'
So how to input argument?

See the several example

>python test1.py -z 1234 -n kjh
1234
kjh
---------
1234
kjh

>python test1.py
usage: test1.py [-h] -z ZIP -n NAME
test1.py: error: the following arguments are required: -z/--zip, -n/--name


>python test1.py -h
usage: test1.py [-h] -z ZIP -n NAME
optional arguments:
  -h, --help            show this help message and exit
  -z ZIP, --zip ZIP     input zip code
  -n NAME, --name NAME  input your name

you can send argument param
-z or --zip for zip code
-n or --name for name string


Thank you.

reference : https://docs.python.org/3/library/argparse.html


1/10/2019

pipenv command summarising.

referenced from :

install
$ pip install pipenv
 brew install pipenv

make virtualenv
$ mkdir myenv
$ cd myenv
$ pipenv --python 3.6


install requirements pipenv
$ cd my_project
$ pipenv install

pipenv package install & uninstall
$ pipenv install beautifulsoup4
 pipenv uninstall beautifulsoup4

freeze → pip freeze > "requirements.txt"
$ pipenv lock

install package to development version
$ pipenv install --dev pytest


install development version requirements 
$ pipenv install --dev

activate pipenv virtualenv
$ pipenv shell

deactivate pipenv virtualenv
$ exit


run pipenv without activate
$ pipenv run which python
$ pipenv run python my_project.py


Python interpreter setting in Visual studio code