Buy Me a Coffee

Bash Handbook (馃毀Continuous Update)

1. Check if a file path represented by environment variable exists [[ "$(cat ${ENV_VARIABLE})" ]] || printf "env is not exported." 2. Get the file name from the full path echo "$basename -a /home/foo/abc.txt" # Output abc.txt 3. Extract the specific cell value from a table output For example, the output of the command nomad node status -address=https://127.0.0.1:4646 ID DC Name Class Drain Eligibility Status d88b0888 dc1 oscarzhou-B550-AORUS-ELITE-AX-V2 <none> false eligible ready If we want to get value of the datacenter dc1 where is [2,2] in the array. The solution is ...

[Golang] How to import a package on the specific version

In Golang, when a package is imported, by default the codebase of the package鈥檚 default branch will be used by the caller project. However, sometimes we want to import a package鈥檚 specific branch codebase. For example, the specific version fixed a bug where we can鈥檛 wait until the repository maintainer merges the pull request. So in this post, I will walk you through how to specify a package version in your Golang project. Let me take an example to help explain better. ...

Git Handbook (馃毀Continuous Update)

1. Discard the changes git checkout -- . 2. Create a new branch git checkout -b <branch_name> # or git branch <branch_name> 3. Cache the password git config --global credential.helper store git config --global credential.helper cache 4. Stash the current changes git stash 5. Recovery/Apply the stash to the current branch git stash list git stash apply stash@{stash_index} # Most often we recover the stash@{0}, so we also can use below git stash apply 6. Configure username and email locally Sometime we need to configure a different username and email for the specific repository ...

[Dokku] Command Cheatsheet

A quick reference guide for commonly used Dokku commands. 1. Create and list app # Create app dokku apps:create <app_name> # List app dokku apps:list 2. Set domains # Set app's domain dokku domains:set <app_name> app.example.com # Set global domain dokku domains:set-global example.com 3. Join app to a specific network # List all networks dokku network:list # Add an app to a specific network dokku network:set <app_name> initial-network <target_network> 4. Show the app鈥檚 configuration dokku config:show <app_name> 5. Manully restart an app dokku ps:rebuild <app_name> 6. Bind app container to all interface bind to all interfaces (0.0.0.0), so the container can be accessed by external request. However, the host port will be randomly assigned. ...

[Dokku] How to set up dokku to deploy docker image

About installing the dokku, I have written another post before: How to install Dokku with Portainer. So I will assume that you have Dokku installed in your server in this post. 1. Environment Setting Dokku: version: 0.27.5. HTTP port: 80, HTTPS port: 443, SSH port: 5022 IP of remote server where the Dokku is installed: 166.23.44.25 (example) Domain: example.com Name of App that will be deployed by Dokku: blog Port of App: 3000 2. SSH Configuration Generate ssh key public file id_rsa.pub ssh-keygen -o We will name the file as dokku_rsa, then you will see two files are generated: dokku_rsa and dokku_rsa.pub. ...

[Dokku] Network understanding

When I ran up Dokku container, I map the host port 8080 to Dokku container port 80. With this configuration, all external requests to Dokku have to reach the host port 8080 first and then they can reach the app deployed by Dokku. In Dokku container, Dokku server still listens to the port 80, 443, 22. Therefore, the port mapping from host to Dokku container looks like 8080:80 8443:443 5022:22 Again in Dokku container, the app鈥檚 nginx should listen to port 80. It鈥檚 because external requests will hit host port 8080, then will be converted to Dokku container port 80. Afterwards, Dokku app鈥檚 nginx can detect the requests and route them to the matching app according to the domain name. ...

[Dokku] How to install Dokku with Portainer

We can easily figure out how to set up Dokku by following the instructions on Dokku website. But for me, I like to host services in docker container as it will bring a clearer structure when it comes to host multiple services in a single machine. In this post, I will assume that you already had some idea about what Dokku is. If not, you can find more information here. In the title, I also mentioned another tool called Portainer. Basically it is a management tool of docker container and kubernete cluster with UI. But it is actually much more than that. (I feel I am digging a bit hole while introducing more and more tools). ...

[DroneCI] How to Configure Pipeline to Build and Push Docker Image

Sometimes we need to build Dockerfile to the docker image and push it to registry in CI pipeline. For instance, my development environment is windows/amd64, but my VPS is linux/arm64. At the end, I want to host the service in my VPS. Thus, it will be easy to build the docker image inside the CI pipeline. In this post, I will show how to configure the pipeline to build and push docker image in DroneCI, which is a self-service Continuous Integration platform for busy development teams. ...

[Golang] Direct request from http to https with reverse proxy

Let鈥檚 say we have a reverse proxy. The incoming request is HTTP, the target server hosts HTTPs APIs with self-signed TLS certificates. It is very common that we change the URL host or path with reverse proxy, so that the request can be directed a different API. However, in this case, we also need to add the self-signed certificates in reverse proxy. The below example will show how to achieve it. ...

[Nomad] How to mount the host path to docker task

Recently I came across a problem where I need to share the host path to Nomad docker task. I have to say that the official document about this part does not explain very clear. I spent quite long time to find the solution. Note that this is not about mounting the host volume to Nomad docker task. Just mount pure folder in host filesystem to Nomad docker task. It is equivalent to the docker command like ...

DigitalOcean Referral Badge
Sign up to get $200, 60-day account credit !