Add Dev Container
This commit is contained in:
Родитель
bb671a56e7
Коммит
79d5969380
|
@ -0,0 +1,113 @@
|
|||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
FROM ubuntu:20.04
|
||||
|
||||
# Instructs apt-get to run without a terminal
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# Terraform, providers and tflint versions
|
||||
ARG TERRAFORM_VERSION=1.2.9
|
||||
ARG AZURERM_VERSION=3.23.0
|
||||
ARG RANDOM_VERSION=3.4.3
|
||||
ARG TIME_VERSION=0.8.0
|
||||
ARG TFLINT_VERSION=0.40.0
|
||||
ARG TFLINT_AZURERM=0.18.0
|
||||
|
||||
# Azure CLI version
|
||||
ARG AZURE_CLI_VERSION=2.40.0-1~focal
|
||||
|
||||
# Bicep version
|
||||
ARG BICEP_VERSION=v0.10.61
|
||||
|
||||
# Update distro (software-properties-common installs the add-apt-repository command)
|
||||
RUN apt-get update \
|
||||
&& apt-get -y install --no-install-recommends apt-utils software-properties-common 2>&1 \
|
||||
&& apt-get dist-upgrade -y
|
||||
|
||||
# Install prerequisites
|
||||
RUN add-apt-repository ppa:git-core/ppa \
|
||||
&& apt-get install -y \
|
||||
apt-transport-https \
|
||||
wget \
|
||||
unzip \
|
||||
git \
|
||||
ca-certificates \
|
||||
curl \
|
||||
lsb-release \
|
||||
gnupg \
|
||||
sudo \
|
||||
shellcheck
|
||||
|
||||
# Install Terraform and tflint
|
||||
RUN wget -O terraform.zip https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip \
|
||||
&& wget -O tflint.zip https://github.com/terraform-linters/tflint/releases/download/v${TFLINT_VERSION}/tflint_linux_amd64.zip \
|
||||
&& unzip ./terraform.zip -d /usr/local/bin/ \
|
||||
&& unzip ./tflint.zip -d /usr/local/bin/ \
|
||||
&& rm terraform.zip \
|
||||
&& rm tflint.zip
|
||||
|
||||
# Download Terraform providers (plugins)
|
||||
# Setting the TF_PLUGIN_CACHE_DIR environment variable instructs Terraform to search that folder for plugins first
|
||||
ENV TF_PLUGIN_CACHE_DIR=/usr/lib/tf-plugins
|
||||
ENV TFLINT_PLUGIN_DIR=/usr/lib/tflint-plugins
|
||||
ARG AZURERM_LOCAL_PATH="${TF_PLUGIN_CACHE_DIR}/registry.terraform.io/hashicorp/azurerm/${AZURERM_VERSION}/linux_amd64"
|
||||
ARG RANDOM_LOCAL_PATH="${TF_PLUGIN_CACHE_DIR}/registry.terraform.io/hashicorp/random/${RANDOM_VERSION}/linux_amd64"
|
||||
ARG TIME_LOCAL_PATH="${TF_PLUGIN_CACHE_DIR}/registry.terraform.io/hashicorp/time/${TIME_VERSION}/linux_amd64"
|
||||
ARG AZURERM_PROVIDER=https://releases.hashicorp.com/terraform-provider-azurerm/${AZURERM_VERSION}/terraform-provider-azurerm_${AZURERM_VERSION}_linux_amd64.zip
|
||||
ARG RANDOM_PROVIDER=https://releases.hashicorp.com/terraform-provider-random/${RANDOM_VERSION}/terraform-provider-random_${RANDOM_VERSION}_linux_amd64.zip
|
||||
ARG TIME_PROVIDER=https://releases.hashicorp.com/terraform-provider-time/${TIME_VERSION}/terraform-provider-time_${TIME_VERSION}_linux_amd64.zip
|
||||
ARG AZURERM_TFLINT_PLUGIN=https://github.com/terraform-linters/tflint-ruleset-azurerm/releases/download/v${TFLINT_AZURERM}/tflint-ruleset-azurerm_linux_amd64.zip
|
||||
RUN wget -O azurerm.zip ${AZURERM_PROVIDER} \
|
||||
&& wget -O random.zip ${RANDOM_PROVIDER} \
|
||||
&& wget -O time.zip ${TIME_PROVIDER} \
|
||||
&& wget -O tflintazurerm.zip ${AZURERM_TFLINT_PLUGIN} \
|
||||
&& mkdir -p ${AZURERM_LOCAL_PATH} \
|
||||
&& mkdir -p ${RANDOM_LOCAL_PATH} \
|
||||
&& mkdir -p ${TIME_LOCAL_PATH} \
|
||||
&& unzip azurerm.zip -d ${AZURERM_LOCAL_PATH} \
|
||||
&& unzip random.zip -d ${RANDOM_LOCAL_PATH} \
|
||||
&& unzip time.zip -d ${TIME_LOCAL_PATH} \
|
||||
&& unzip tflintazurerm.zip -d ${TFLINT_PLUGIN_DIR} \
|
||||
&& rm azurerm.zip \
|
||||
&& rm random.zip \
|
||||
&& rm time.zip \
|
||||
&& rm tflintazurerm.zip
|
||||
|
||||
# Install the Microsoft package key
|
||||
RUN wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb \
|
||||
&& dpkg -i packages-microsoft-prod.deb \
|
||||
&& rm packages-microsoft-prod.deb
|
||||
|
||||
# Install the Microsoft signing key
|
||||
RUN curl -sL https://packages.microsoft.com/keys/microsoft.asc | \
|
||||
gpg --dearmor | \
|
||||
tee /etc/apt/trusted.gpg.d/microsoft.gpg > /dev/null
|
||||
|
||||
# Install the AZ CLI repository
|
||||
RUN AZ_REPO=$(lsb_release -cs) \
|
||||
&& echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" | \
|
||||
tee /etc/apt/sources.list.d/azure-cli.list
|
||||
|
||||
# Install AZ CLI
|
||||
RUN apt-get update && apt-get install -y azure-cli=${AZURE_CLI_VERSION}
|
||||
|
||||
# Install Bicep
|
||||
RUN curl -Lo /usr/local/bin/bicep https://github.com/Azure/bicep/releases/download/${BICEP_VERSION}/bicep-linux-x64 \
|
||||
&& chmod +x /usr/local/bin/bicep
|
||||
|
||||
# Clean up
|
||||
RUN apt-get autoremove -y \
|
||||
&& apt-get clean -y \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Add the vscode user
|
||||
ARG USERNAME=vscode
|
||||
ARG USER_UID=1000
|
||||
ARG USER_GID=$USER_UID
|
||||
RUN groupadd --gid $USER_GID $USERNAME \
|
||||
&& useradd -s /bin/bash --uid $USER_UID --gid $USERNAME -m $USERNAME \
|
||||
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
|
||||
&& chmod 0440 /etc/sudoers.d/$USERNAME
|
||||
|
||||
# Reset to the default value
|
||||
ENV DEBIAN_FRONTEND=dialog
|
|
@ -0,0 +1,78 @@
|
|||
# Azure NoOps Accelerator - Development Container Guide
|
||||
|
||||
This folder contains configuration for a development container. Usage instructions are below. For more details see the VS Code documentation on [developing in a container](https://code.visualstudio.com/docs/remote/containers).
|
||||
|
||||
## How to use the remote container
|
||||
|
||||
All configuration related to the development container is in the `.devcontainer` directory.
|
||||
|
||||
- `devcontainer.json`: Configuration settings for the development container
|
||||
- `Dockerfile`: Docker container definition for the development container
|
||||
|
||||
### Step-by-Step
|
||||
|
||||
1. Ensure you have the prerequisites installed as described here: <https://code.visualstudio.com/docs/remote/containers>
|
||||
|
||||
- Windows: Docker Desktop 2.0+ on Windows 10 Pro/Enterprise. Windows 10 Home (2004+) requires Docker Desktop 2.3+ and the WSL 2 back-end. (Docker Toolbox is not supported. Windows container images are not supported.)
|
||||
- macOS: Docker Desktop 2.0+.
|
||||
- Linux: Docker CE/EE 18.06+ and Docker Compose 1.21+. (The Ubuntu snap package is not supported.)
|
||||
|
||||
1. Clone this repository
|
||||
|
||||
```BASH
|
||||
git clone https://github.com/Azure/NoOpsAccelerator
|
||||
```
|
||||
|
||||
2. Change to the root folder of the local workspace for the cloned project, and start VS Code from this root folder (not a sub folder or a parent folder).
|
||||
|
||||
> **NOTE:** be sure to include the trailing "." in the second command.
|
||||
|
||||
```BASH
|
||||
cd anoa
|
||||
code .
|
||||
```
|
||||
|
||||
<!-- markdownlint-disable MD013 -->
|
||||
3. Install the recommended VS Code extensions found in `anoa/.vscode/extensions.json` file. Including the "Remote Development" extension from Microsoft.
|
||||
|
||||
> **NOTE:** When VS Code is correctly started from the MissionLZ project root directory, you should see folders named `.devcontainer`, `.vscode`, and `src` at the root of the VS Code Explorer pane. In the startup process, VS Code reads the file `.vscode/extensions.json` (relative from the current working directory) and may prompt the user to install any extensions referenced here that are not already installed.
|
||||
|
||||
<!-- markdownlint-enable MD013 -->
|
||||
|
||||
4. In the VS Code command palette `(Ctrl + Shift + P)`, run this command:
|
||||
|
||||
```VSCODE
|
||||
Remote-Containers: Reopen in Container
|
||||
```
|
||||
|
||||
> **NOTE:** The container will build on your machine. The first build may take several minutes; the `Reopen in Container` command will be much faster after the initial container build, and VS Code will prompt you if the container needs to be rebuilt when the `Dockerfile` or container configuration settings have changed.
|
||||
|
||||
When logged into the devcontainer's terminal, the working directory changes to `vscode@anoa-dev:/workspaces/anoa$`
|
||||
|
||||
### Step-by-Step (VS Code alternative)
|
||||
|
||||
(*Optional*) If you'd like to interact with the devcontainer's terminal from another terminal other than VS Code's built in terminal, you can use the `docker exec` command.
|
||||
|
||||
> **NOTE:** VS Code attaches to the container as the user named "vscode", so you have to do the same thing when attaching to a BASH session in the container by specifying the user as an argument to the `docker exec` command. If you do not specify the user then you will be connected as root, which will cause permissions issues in git (if you are launching VS Code from WSL).
|
||||
|
||||
```BASH
|
||||
docker exec --interactive --tty --user vscode anoa-dev /bin/bash
|
||||
```
|
||||
|
||||
Or, the equivalent short form below:
|
||||
|
||||
```BASH
|
||||
docker exec -it -u vscode anoa-dev /bin/bash
|
||||
```
|
||||
|
||||
### Authenticating to GitHub
|
||||
|
||||
Authenticating to GitHub is not required for cloning the Mission LZ repo, but you may want to set it up for times when you need authentication, like when you need to push a new branch.
|
||||
|
||||
The Windows Git Credential Manager can be configured to work from WSL to help with complex authentication patterns like two-factor authentication. See the [documentation here](https://docs.microsoft.com/en-us/windows/wsl/tutorials/wsl-git#git-credential-manager-setup).
|
||||
|
||||
For WSL, this is the command to run for configuring the Windows Credential Manager:
|
||||
|
||||
```BASH
|
||||
git config --global credential.helper "/mnt/c/Program\ Files/Git/mingw64/libexec/git-core/git-credential-manager.exe"
|
||||
```
|
|
@ -0,0 +1,41 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
{
|
||||
"name": "anoa-dev",
|
||||
"build": {
|
||||
"dockerfile": "Dockerfile"
|
||||
},
|
||||
// Set *default* container specific settings.json values on container create.
|
||||
"settings": {
|
||||
"terminal.integrated.profiles.linux": {
|
||||
"bash": {
|
||||
"path": "/bin/bash"
|
||||
}
|
||||
},
|
||||
"terminal.integrated.defaultProfile.linux": "bash"
|
||||
},
|
||||
// Add the IDs of extensions you want installed when the container is created.
|
||||
"extensions": [
|
||||
"hashicorp.terraform",
|
||||
"ms-vscode-remote.vscode-remote-extensionpack",
|
||||
"davidanson.vscode-markdownlint",
|
||||
"github.vscode-pull-request-github",
|
||||
"timonwong.shellcheck",
|
||||
"ms-azuretools.vscode-bicep",
|
||||
"bierner.markdown-preview-github-styles",
|
||||
"ms-azure-devops.azure-pipelines"
|
||||
],
|
||||
// Additional args to pass to the 'docker run' command
|
||||
"runArgs": [
|
||||
"--name",
|
||||
"anoa-dev",
|
||||
"--hostname",
|
||||
"anoa-dev"
|
||||
],
|
||||
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||
// "forwardPorts": [],
|
||||
// Use 'postCreateCommand' to run commands after the container is created.
|
||||
// "postCreateCommand": "uname -a",
|
||||
// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
|
||||
"remoteUser": "vscode"
|
||||
}
|
Загрузка…
Ссылка в новой задаче