coding-to-music / coding-to-music.github.io

https://pandemic-overview.readthedocs.io/en/latest/index.html
MIT License
2 stars 8 forks source link

Build Chromebook Linux development environment in a fast, repeatable way #122

Open coding-to-music opened 3 years ago

coding-to-music commented 3 years ago

Build Chromebook Linux development environment in a fast, repeatable way

load recent saved Chromebook image

https://pandemic-overview.readthedocs.io/en/latest/myGuides/General-computer-setup.html#setup-your-computer-we-will-cover-each-item

Setting up the python virtualenv development environment on Debian Linux #77 https://github.com/coding-to-music/coding-to-music.github.io/issues/77

Getting started after deploying Kubernetes Monitoring Stack - Grafana, Prometheus, Alert-Manager, Metrics-server #118 https://github.com/coding-to-music/coding-to-music.github.io/issues/118

Monitor Chromebook Need to download and install Prometheus and set it as a data source

Create Digitalocean k8s from command line https://github.com/coding-to-music/doks-example

Digitalocean

loaded snapshot was able to connect to github gh was installed but needed auth docker installed doctl installed vscode installed ansible installed dotfiles and bash aliases are there

Chromebook

Ansible install

https://docs.ansible.com/ansible/latest/user_guide/connection_details.html#running-against-localhost

https://docs.ansible.com/ansible/latest/user_guide/sample_setup.html

coding-to-music commented 3 years ago

After loading saved Chromebook Linux image

tmc@penguin:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vdb        7.5G  3.2G  4.0G  45% /

Installed:

Not Installed:

Now Install

sudo apt-get install apt-transport-https
sudo apt-get update
sudo apt-get install code

sudo apt install gnome-keyring

Docker

1) Set up the repository

A) Update the apt package index and install packages to allow apt to use a repository over HTTPS:

 sudo apt-get update
 sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

B) Add Docker’s official GPG key:

curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

C) Use the following command to set up the stable repository.

 echo \
  "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

2) Install Docker Engine

This procedure works for Debian on x86_64 / amd64, armhf, arm64, and Raspbian.

A) Update the apt package index, and install the latest version of Docker Engine and containerd, or go to the next step to install a specific version:

 sudo apt-get update
 sudo apt-get install docker-ce docker-ce-cli containerd.io

B) To install a specific version of Docker Engine, list the available versions in the repo, then select and install:

List the versions available in your repo:

 apt-cache madison docker-ce

You can install the many available versions listed in the apt-cache

C) Install a specific version using the version string from the second column, for example, 5:18.09.1~3-0~debian-stretch .

 sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io

kubectl Helm Minikube Kubectl

coding-to-music commented 3 years ago

Check Space at this point

tmc@penguin:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vdb        7.5G  3.8G  3.0G  57% /
none            492K     0  492K   0% /dev
devtmpfs        1.4G     0  1.4G   0% /dev/tty
/dev/vdb        7.5G  3.8G  3.0G  57% /dev/wl0
tmpfs           100K     0  100K   0% /dev/lxd
tmpfs           100K     0  100K   0% /dev/.lxd-mounts
run             1.4G   28K  1.4G   1% /dev/.host_ip
/dev/root       173M  170M     0 100% /dev/.ssh/sshd_config
9p              1.9G  772K  1.9G   1% /mnt/chromeos
tmpfs           1.4G     0  1.4G   0% /mnt/external
/dev/vda         50M   50M     0 100% /opt/google/cros-containers
tmpfs           1.4G   23M  1.4G   2% /dev/shm
tmpfs           1.4G  132K  1.4G   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           1.4G     0  1.4G   0% /sys/fs/cgroup
tmpfs           278M   36K  278M   1% /run/user/1000

Continue here

Verify that Docker Engine is installed correctly by running the hello-world image.

 sudo docker run hello-world

non-su for docker https://docs.docker.com/engine/install/debian/

coding-to-music commented 3 years ago

https://github.com/docker/docker.github.io/blob/master/engine/install/linux-postinstall.md

Interesting meta


description: Optional post-installation steps for Linux keywords: Docker, Docker documentation, requirements, apt, installation, ubuntu, install, uninstall, upgrade, update title: Post-installation steps for Linux redirect_from:

This section contains optional procedures for configuring Linux hosts to work better with Docker.

Manage Docker as a non-root user

The Docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root and other users can only access it using sudo. The Docker daemon always runs as the root user.

If you don't want to preface the docker command with sudo, create a Unix group called docker and add users to it. When the Docker daemon starts, it creates a Unix socket accessible by members of the docker group.

Warning

The docker group grants privileges equivalent to the root user. For details on how this impacts security in your system, see Docker Daemon Attack Surface. {: .warning}

Note:

To run Docker without root privileges, see Run the Docker daemon as a non-root user (Rootless mode).

To create the docker group and add your user:

  1. Create the docker group.

    $ sudo groupadd docker
  2. Add your user to the docker group.

    $ sudo usermod -aG docker $USER

Reboot the computer - not just logout/login

  1. Log out and log back in so that your group membership is re-evaluated.

    If testing on a virtual machine, it may be necessary to restart the virtual machine for changes to take effect.

    On a desktop Linux environment such as X Windows, log out of your session completely and then log back in.

    On Linux, you can also run the following command to activate the changes to groups:

    $ newgrp docker 
  2. Verify that you can run docker commands without sudo.

    $ docker run hello-world

    This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.

    If you initially ran Docker CLI commands using sudo before adding your user to the docker group, you may see the following error, which indicates that your ~/.docker/ directory was created with incorrect permissions due to the sudo commands.

    WARNING: Error loading config file: /home/user/.docker/config.json -
    stat /home/user/.docker/config.json: permission denied

    To fix this problem, either remove the ~/.docker/ directory (it is recreated automatically, but any custom settings are lost), or change its ownership and permissions using the following commands:

    $ sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
    $ sudo chmod g+rwx "$HOME/.docker" -R
coding-to-music commented 3 years ago

dotfiles repo python --version gh doctl ansible digitalocean token SSH keys to Digitalocean SSH keys to GitHub tree ncdu

coding-to-music commented 3 years ago

Setup Dotfiles, GitHub SSH token, Doctl token

git clone git@github.com:coding-to-music/dotfiles.git
Cloning into 'dotfiles'...

cp dotfiles/.bash_aliases .

sudo apt upgrade
sudo apt install ansible

Check Space

tmc@penguin:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vdb        7.5G  4.0G  2.8G  59% /
none            492K     0  492K   0% /dev
devtmpfs        1.4G     0  1.4G   0% /dev/tty
/dev/vdb        7.5G  4.0G  2.8G  59% /dev/wl0
tmpfs           100K     0  100K   0% /dev/lxd
tmpfs           100K     0  100K   0% /dev/.lxd-mounts
run             1.4G   28K  1.4G   1% /dev/.host_ip
/dev/root       173M  170M     0 100% /dev/.ssh/sshd_config
9p              1.9G  772K  1.9G   1% /mnt/chromeos
tmpfs           1.4G     0  1.4G   0% /mnt/external
/dev/vda         50M   50M     0 100% /opt/google/cros-containers
tmpfs           1.4G   21M  1.4G   2% /dev/shm
tmpfs           1.4G  128K  1.4G   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           1.4G     0  1.4G   0% /sys/fs/cgroup
tmpfs           278M   40K  278M   1% /run/user/1000

sudo apt install tree
sudo apt install ncdu
sudo apt install tree
sudo apt install htop

GitHub CLI gh

curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo gpg --dearmor -o /usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install gh 
coding-to-music commented 3 years ago

kubectl

Update the apt package index and install packages needed to use the Kubernetes apt repository:

sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl

Download the Google Cloud public signing key:

sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg

Add the Kubernetes apt repository:

echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list

Update apt package index with the new repository and install kubectl:

sudo apt-get update
sudo apt-get install -y kubectl
coding-to-music commented 3 years ago

Kind

https://kind.sigs.k8s.io/docs/user/quick-start/#installation

curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.11.1/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin
coding-to-music commented 3 years ago

minikube start

https://github.com/coding-to-music/coding-to-music.github.io/issues/116

minikube is local Kubernetes, focusing on making it easy to learn and develop for Kubernetes.

minikube Like kind, minikube is a tool that lets you run Kubernetes locally. minikube runs a single-node Kubernetes cluster on your personal computer (including Windows, macOS and Linux PCs) so that you can try out Kubernetes, or for daily development work. #116

All you need is Docker (or similarly compatible) container or a Virtual Machine environment, and Kubernetes is a single command away: minikube start

What you’ll need 2 CPUs or more 2GB of free memory 20GB of free disk space Internet connection Container or virtual machine manager, such as: Docker

coding-to-music commented 3 years ago

doctl

doctl is able to interact with all of your DigitalOcean resources. Below are a few common usage examples #115 https://github.com/coding-to-music/coding-to-music.github.io/issues/115

Get the tar file

64 bit Linux OS

curl -s https://api.github.com/repos/digitalocean/doctl/releases/latest | grep browser_download_url | cut -d '"' -f 4 | grep linux-amd64 | wget -qi -

untar the file

curl -s https://api.github.com/repos/digitalocean/doctl/releases/latest | grep browser_download_url | cut -d '"' -f 4 | grep linux-amd64 | wget -qi -

tar xvf doctl-1.61.0-linux-amd64.tar.gz 

doctl  <-- this file was created

Move the file to someplace in the $PATH

sudo mv doctl /usr/local/bin

doctl version

doctl version 1.61.0-release

Git commit hash: c46d961
coding-to-music commented 3 years ago

Digitalocean token

doctl auth init
Please authenticate doctl for use with your DigitalOcean account. You can generate a token in the control panel at https://cloud.digitalocean.com/account/api/tokens

Enter your access token: 
Validating token... OK

doctl account ratelimit
Limit    Remaining    Reset
5000     4998         2021-06-18 01:40:33 -0400 EDT

doctl balance get
Month-to-date Balance    Account Balance    Month-to-date Usage    Generated At
4.83                     0.00               4.83                   2021-06-18T05:29:24Z
coding-to-music commented 3 years ago

Clean Up Disk Space

tmc@penguin:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vdb        7.5G  4.0G  2.8G  60% /
none            492K     0  492K   0% /dev
devtmpfs        1.4G     0  1.4G   0% /dev/tty
/dev/vdb        7.5G  4.0G  2.8G  60% /dev/wl0
tmpfs           100K     0  100K   0% /dev/lxd
tmpfs           100K     0  100K   0% /dev/.lxd-mounts
run             1.4G   28K  1.4G   1% /dev/.host_ip
/dev/root       173M  170M     0 100% /dev/.ssh/sshd_config
9p              1.9G  772K  1.9G   1% /mnt/chromeos
tmpfs           1.4G     0  1.4G   0% /mnt/external
/dev/vda         50M   50M     0 100% /opt/google/cros-containers
tmpfs           1.4G   21M  1.4G   2% /dev/shm
tmpfs           1.4G  128K  1.4G   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           1.4G     0  1.4G   0% /sys/fs/cgroup
tmpfs           278M   48K  278M   1% /run/user/1000

https://itsfoss.com/clear-apt-cache/

https://itsfoss.com/free-up-space-ubuntu-linux/

coding-to-music commented 3 years ago

Get rid of packages that are no longer required [Recommended]

https://itsfoss.com/free-up-space-ubuntu-linux/ If you read the apt-get commands guide, you might have come across the apt-get command option ‘autoremove’.

This option removes libs and packages that were installed automatically to satisfy the dependencies of an installed package. If that package is removed, these automatically installed packages are useless in the system.

It also removes old Linux kernels that were installed from automatically in the system upgrade.

It’s a no-brainer command that you can run from time to time to make some free space on your Ubuntu system:

sudo apt-get autoremove

As you can see, this command is going to free up zero 0 Mb of free space in my system, but it is a fresh install so far.

tmc@penguin:~$ sudo apt-get autoremove

Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

tmc@penguin:~$ sudo apt-get update

Hit:1 https://cli.github.com/packages stable InRelease
Hit:2 https://deb.debian.org/debian buster InRelease                                                                                                     
Get:3 https://deb.debian.org/debian-security buster/updates InRelease [65.4 kB]                                                                          
Ign:4 https://storage.googleapis.com/cros-packages/91 buster InRelease                                                                                   
Hit:5 https://download.docker.com/linux/debian buster InRelease                                                                                          
Hit:6 https://storage.googleapis.com/cros-packages/91 buster Release                                                                                   
Hit:8 https://packages.microsoft.com/repos/vscode stable InRelease                                                               
Get:7 https://packages.cloud.google.com/apt kubernetes-xenial InRelease [9,383 B]
Get:9 https://deb.debian.org/debian-security buster/updates/main amd64 Packages [292 kB]
Fetched 367 kB in 2s (164 kB/s)  
Reading package lists... Done

tmc@penguin:~$ sudo apt-get autoremove

Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
coding-to-music commented 3 years ago

Clean up APT cache in Ubuntu

Ubuntu uses APT (Advanced Package Tool) for installing, removing and managing software on the system, and in doing so it keeps a cache of previously downloaded and installed packages even after they’ve been uninstalled.

The APT package management system keeps a cache of DEB packages in /var/cache/apt/archives. Over time, this cache can grow quite large and hold a lot of packages you don’t need.

You can see the size of this cache with the du command below:

sudo du -sh /var/cache/apt 
253M    /var/cache/apt

As you can see, I have over 500 Mb of cache storage. When you are almost out of space, this 500 Mb can make a lot of difference.

Clean up cache in Ubuntu Linux Cleaning up cache will free up space Now, you have two ways to clean the APT cache.

Either remove only the outdated packages, like those superseded by a recent update, making them completely unnecessary.

sudo apt-get autoclean
Reading package lists... Done
Building dependency tree       
Reading state information... Done

Or delete apt cache in its entirety (frees more disk space):

sudo apt-get clean

Clear systemd journal logs [new image so not much space to reclaim]

Every Linux distribution has a logging mechanism that help you investigate what’s going on your system. You’ll have kernel logging data, system log messages, standard output and errors for various services in Ubuntu.

The problem is that over the time, these logs take a considerable amount of disk space. You can check the log size with this command:

journalctl --disk-usage

tmc@penguin:~$ journalctl --disk-usage
Hint: You are currently not seeing messages from other users and the system.
      Users in groups 'adm', 'systemd-journal' can see all messages.
      Pass -q to turn off this notice.
Archived and active journals take up 16.0M in the file system.

tmc@penguin:~$ sudo journalctl --disk-usage
Archived and active journals take up 32.0M in the file system.

Now, there are ways to clean systemd journal logs. The easiest for you is to clear the logs that are older than a certain days.

sudo journalctl --vacuum-time=3d

Here’s an example:

abhishek@itsfoss:~$ journalctl --disk-usage

Archived and active journals take up 1.8G in the file system.

abhishek@itsfoss:~$ sudo journalctl --vacuum-time=3d

Vacuuming done, freed 1.7G of archived journals from /var/log/journal/1b9ab93094fa2984beba73fd3c48a39c

coding-to-music commented 3 years ago

Confirm proper operation - everything is installed

To validate correct setup

echo "always good to update the package manager apt"

sudo apt update

echo "see how we are configured with GitHub"

git config --list

echo "Check that GitHub can be reached via SSH"

ssh -vT git@github.com

echo "NodeJS" 
apt install node $OPTIONS

echo "Python 3"
apt install python $OPTIONS

echo "Golang"
apt install go $OPTIONS

echo "validate vscode install"
code --version

echo "validate ansible" 
ansible --version

echo "Run this command to test the connection:"

ansible -m ping TestClient

echo "Verify that Docker Engine is installed correctly by running the hello-world image as sudo"

sudo docker run hello-world

echo "Verify that you can run docker commands without sudo"

docker run hello-world

echo "htop"
apt install htop $OPTIONS

echo "Show directory structure with excellent formatting"
apt install tree $OPTIONS
coding-to-music commented 3 years ago

Install Go golang

Go golang is an open source programming language that makes it easy to build simple, reliable, and efficient software.

https://golang.org/

https://golang.org/doc/install

download the file https://golang.org/dl/

Extract the archive you downloaded into /usr/local, creating a Go tree in /usr/local/go.

Important: This step will remove a previous installation at /usr/local/go, if any, prior to extracting. Please back up any data before proceeding.

For example, run the following as root or through sudo:

sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.16.5.linux-amd64.tar.gz

Add /usr/local/go/bin to the PATH environment variable.

You can do this by adding the following line to your $HOME/.profile or /etc/profile (for a system-wide installation):

export PATH=$PATH:/usr/local/go/bin

Note: Changes made to a profile file may not apply until the next time you log into your computer. To apply the changes immediately, just run the shell commands directly or execute them from the profile using a command such as source

$HOME/.profile.

# load the .bash_aliases file
source ~./.bashrc

Verify that you've installed Go by opening a command prompt and typing the following command:

go version

Confirm that the command prints the installed version of Go.

coding-to-music commented 3 years ago

CLI Color - A command-line color library with true color support, universal API methods