Recently, I was enthusiastic about the Windows environment and WSL (Windows Subsystem for Linux) 2, and I felt that CircleCI was not enough, so I created an environment where I can test CircleCI. It's easy to install except when you're worried that you don't have to install Docker in Linux installed with WSL.
TL;DR
Use dism.exe
to install the Windows subsystem and virtual machine platform for Linux required for WSL.
This package will not take effect until ** restart, so ** restart Windows after installation.
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Then install the Linux kernel update package. Install the file downloaded from the link.
https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi
The following command specifies the default version for the newly installed Linux distribution to be installed in WSL2 format.
wsl --set-default-version 2
If you do not do this, the next Linux installation will be installed in WSL1 format.
The link at https://aka.ms/wslstore opens a gallery of Linux distributions that you can install in the Microsoft Store. Install Ubuntu from there.
After installation, click Ubuntu from the start menu to start it. ** It will take a few minutes due to the initial setting, but it will start immediately from the next time.
You will be asked for the user name and password to use with Ubuntu, so set them here.
When you're done, run the following command on your Windows terminal (Command Prompt / PowerShell) to see a list of your installed Linux distributions.
wsl -l -v
You should see something like this
NAME STATE VERSION
* Ubuntu Running 2
If VERSION is not 2, it is introduced in WSL1. To convert to VERSION 2, install the "Linux Kernel Update Package" and then set the WSL version to 2 for the Linux installed in WSL1.
wsl --set-version Ubuntu 2
The official documentation states that this VERSION can be changed in both directions.
I will also update the package on the Ubuntu side. First, change the source of the package to the Japanese server so that the update will be faster.
cd /etc/apt
sudo sed -i.bak -e "s/http:\/\/archive\.ubuntu\.com/http:\/\/jp\.archive\.ubuntu\.com/g" sources.list
You can update the Ubuntu package with the following command:
sudo apt update
sudo apt upgrade -y
Ubuntu can be started from the start menu, but with the introduction of Windows Terminal
You can tab the terminals such as, etc. into one window. Starting each terminal is as easy as creating a tab.
Windows Terminal can be installed from the Microsoft Store where Ubuntu is installed.
Introduce Docker for Docker Desktop for Windows. ** Docker will not be installed on Ubuntu side. ** ** Click Get Docker from the official page below to get the installer. https://hub.docker.com/editions/community/docker-ce-desktop-windows
When you run the installer, the "Enable WSL 2 Windows Features" checkbox should be checked, so check it and continue the installation. When Docker Desktop starts and the tutorial window appears, close it.
You can see that the Docker virtual environment has started up with wsl -l -v
from the terminal on the Windows side.
wsl -l -v
NAME STATE VERSION
* Ubuntu Running 2
docker-desktop-data Running 2
docker-desktop Running 2
You can execute Docker commands from a Windows terminal.
docker run -it hello-world
If you pull any container and start it, it will be registered in the list of docker images
.
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest bf756fb1ae65 10 months ago 13.3kB
The same Dockewr operation can be performed from the Ubuntu side, which should not have been installed separately. You can now run it locally with the CircleCI CLI that uses Docker.
Work on an Ubuntu device. Install the CircleCI CLI with the following command:
sudo sh -c "curl -fLSs https://circle.ci/cli | bash"
Register your CircleCI account with the CLI. If you do not have a CircleCI account, click Create a new one.
After installing the CircleCI CLI, run circleci setup
.
When "CircleCI API Token" is displayed, click your icon displayed at the bottom right of the CircleCI dashboard to display User Settings.
Click Personal API Tokens to display a list of API Tokens. Click Create New Token to create a new one.
If you enter the name of the newly created API Token, the Token will be displayed, but ** because it cannot be displayed again **, copy it, enter it in the CLI settings earlier, and then close the dialog. Let's do it.
The username is displayed on the CircleCI CLI screen to see if you can communicate using the API Token.
Local execution of CircleCI requires a Git-managed project. Run git init
after creating a new directory to use Git.
mkdir sample-project
cd sample-project
git init
When using Git for the first time on Ubuntu, you need to register the name and email address of the committed user.
Registration example
git config --global user.email "[email protected]"
git config --global user.name "ysd-marrrr"
Create some file to make a Git commit.
echo "Hello World!" > README.md
git add README.md
git commit -m "1st commit"
After committing something with Git, create a CircleCI configuration file.
mkdir .circleci
Create a config.yml
in the .circleci
directory.
yml:./.circleci/config.yml
version: 2.0
jobs:
build:
docker:
- image: circleci/ruby:2.4.2-jessie-node
steps:
- checkout
- run: echo "Hello World"
You can check the configuration file before running locally. You can see that the configuration file is correct with "Config file at .circleci / config.yml is valid."
circleci config validate
Run it locally when you're ready.
circleci local execute
If Success! Is displayed, it is successful!
If you execute docker images
here, the CircleCI images used in the series of operations are registered locally.
If you execute docker images
from a Windows terminal in the same way, CircleCI images will be registered.
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
circleci/picard latest b85648cb1ea4 45 hours ago 94.5MB
hello-world latest bf756fb1ae65 10 months ago 13.3kB
circleci/ruby 2.4.2-jessie-node 54898fcdc277 2 years ago 968MB
You can use Docker installed on Windows from Ubuntu! With WSL2 and Docker Desktop for Windows, you don't need to install Docker again on Ubuntu.
Install Windows Subsystem for Linux (WSL) on Windows 10 | Microsoft Docs https://docs.microsoft.com/ja-jp/windows/wsl/install-win10
Use WSL2 as backend for Docker Desktop for Windows | Developers.IO https://dev.classmethod.jp/articles/docker-desktop-for-windows-on-wsl2/
I tried setting up Windows Subsystem for Linux 2 (WSL 2) | Developers.IO https://dev.classmethod.jp/articles/how-to-setup-wsl2/
Installation and initial setup of Ubuntu 18.04 on WSL http://www.aise.ics.saitama-u.ac.jp/~gotoh/HowToInstallUbuntu1804OnWSL.html#toc11
Using CircleCI's Local CLI-CircleCI https://circleci.com/docs/ja/2.0/local-cli/