Last year I was working on a project for deploying Azure services using Ansible, and let me tell you something: Back then a feature like Visual Studio Remote Containers would have helped us so much!
Why? Because just installing Visual Studio Code, the Remote Development Extension Pack, and Docker you have a killer combo that makes it possible to create a Development environment in a snap and share it with your source code.
When I learned about this feature I tought I should create a Developer Container for those who need to work with Azure and Ansible so I went hands on and after collaborating with Chuck Lantz the container definition resulted in the following two files:
devcontainer.json
This file configures the remote container with the specified extensions
1{
2 "name": "Azure Ansible",
3 "dockerFile": "Dockerfile",
4 "runArgs": [
5 // Uncomment the next line if you will use a ptrace-based debugger like C++, Go, and Rust.
6 // "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined",
7 "-v", "/var/run/docker.sock:/var/run/docker.sock"
8 ],
9
10 // Uncomment the next line if you want to publish any ports.
11 // "appPort": [],
12
13 // Uncomment the next line if you want to add in default container specific settings.json values
14 // "settings": { "workbench.colorTheme": "Quiet Light" },
15
16 // Uncomment the next line to run commands after the container is created.
17 // "postCreateCommand": "ansible --version",
18
19 "extensions": [
20 "vscoss.vscode-ansible",
21 "redhat.vscode-yaml",
22 "ms-vscode.azurecli"
23 ]
24}
Dockerfile
This is the Dockerfile with all the tooling for the Development environment.
1#-------------------------------------------------------------------------------------------------------------
2# Copyright (c) Microsoft Corporation. All rights reserved.
3# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
4#-------------------------------------------------------------------------------------------------------------
5
6# Pick any base image, but if you select node, skip installing node. 😊
7FROM debian:9
8
9# Avoid warnings by switching to noninteractive
10ENV DEBIAN_FRONTEND=noninteractive
11
12# Configure apt and install packages
13RUN apt-get update \
14 && apt-get -y install --no-install-recommends apt-utils 2>&1 \
15 #
16 # Verify git, required tools installed
17 && apt-get install -y \
18 git \
19 curl \
20 procps \
21 unzip \
22 apt-transport-https \
23 ca-certificates \
24 gnupg-agent \
25 software-properties-common \
26 lsb-release 2>&1 \
27 #
28 # [Optional] Install Node.js for Azure Cloud Shell support
29 # Change the "lts/*" in the two lines below to pick a different version
30 && curl -so- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash 2>&1 \
31 && /bin/bash -c "source $HOME/.nvm/nvm.sh \
32 && nvm install lts/* \
33 && nvm alias default lts/*" 2>&1 \
34 #
35 # [Optional] For local testing instead of cloud shell
36 # Install Docker CE CLI.
37 && curl -fsSL https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/gpg | apt-key add - 2>/dev/null \
38 && add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]') $(lsb_release -cs) stable" \
39 && apt-get update \
40 && apt-get install -y docker-ce-cli \
41 #
42 # [Optional] For local testing instead of cloud shell
43 # Install the Azure CLI
44 && echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $(lsb_release -cs) main" > /etc/apt/sources.list.d/azure-cli.list \
45 && curl -sL https://packages.microsoft.com/keys/microsoft.asc | apt-key add - 2>/dev/null \
46 && apt-get update \
47 && apt-get install -y azure-cli \
48 #
49 # Install Ansible
50 && apt-get install -y libssl-dev libffi-dev python-dev python-pip \
51 && pip install ansible[azure] \
52 #
53 # Clean up
54 && apt-get autoremove -y \
55 && apt-get clean -y \
56 && rm -rf /var/lib/apt/lists/*
57
58# Switch back to dialog for any ad-hoc use of apt-get
59ENV DEBIAN_FRONTEND=dialog
To learn more about the Azure Ansible Remote Container please check here.
If you want to use Developer Conatianers with WSL 2 start here
Hope it helps!
Comments