Skip to content
This repository was archived by the owner on Nov 30, 2023. It is now read-only.

HashiStack #203

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 140 additions & 0 deletions containers/hashistack/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------
FROM ubuntu:18.04

# This Dockerfile adds a non-root user with sudo access. Use the "remoteUser"
# property in devcontainer.json to use it. On Linux, the container user's GID/UIDs
# will be updated to match your local UID/GID (when using the dockerFile property).
# See https://aka.ms/vscode-remote/containers/non-root-user for details.
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# Docker Compose.
ARG COMPOSE_VERSION=1.24.0

# Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update \
&& apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \
#
# Verify git, zsh, vim, process tools installed
&& apt-get -y install git iproute2 procps zsh unzip neovim \
#
# Install Docker CE CLI
&& apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common lsb-release \
&& curl -fsSL https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/gpg | (OUT=$(apt-key add - 2>&1) || echo $OUT) \
&& add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]') $(lsb_release -cs) stable" \
&& apt-get update \
&& apt-get install -y docker-ce-cli \
#
# Install Docker Compose
&& curl -sSL "https://github.com/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose \
&& chmod +x /usr/local/bin/docker-compose \
#
# Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user.
&& groupadd --gid $USER_GID $USERNAME \
&& useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
# [Optional] Add sudo support for the non-root user
&& apt-get install -y sudo \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME\
&& chmod 0440 /etc/sudoers.d/$USERNAME \
#
# Clean up
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

# Oh-My-ZSH
RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
RUN echo 'alias vim=nvim' >> ~/.zshrc

# Switch back to dialog for any ad-hoc use of apt-get
# TODO: Move this down once everything settles.
ENV DEBIAN_FRONTEND=dialog

# Hashicorp.
WORKDIR /ops

## Consul
ARG CONSUL_VERSION=1.6.1
ARG CONSULDOWNLOAD=https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip
ARG CONSULCONFIGDIR=/etc/consul.d
ARG CONSULDIR=/opt/consul

### Download
RUN curl -L $CONSULDOWNLOAD > consul.zip

### Install
RUN unzip consul.zip -d /usr/local/bin
RUN chmod 0755 /usr/local/bin/consul
RUN chown root:root /usr/local/bin/consul

### Configure
RUN mkdir -p $CONSULCONFIGDIR
RUN chmod 755 $CONSULCONFIGDIR
RUN mkdir -p $CONSULDIR
RUN chmod 755 $CONSULDIR

## Consul Template
ARG CONSUL_TEMPLATE_VERSION=0.20.0
ARG CONSULTEMPLATEDOWNLOAD=https://releases.hashicorp.com/consul-template/${CONSUL_TEMPLATE_VERSION}/consul-template_${CONSUL_TEMPLATE_VERSION}_linux_amd64.zip
ARG CONSULTEMPLATECONFIGDIR=/etc/consul-template.d
ARG CONSULTEMPLATEDIR=/opt/consul-template

### Download
RUN curl -L $CONSULTEMPLATEDOWNLOAD > consul-template.zip

## Install
RUN unzip consul-template.zip -d /usr/local/bin
RUN chmod 0755 /usr/local/bin/consul-template
RUN chown root:root /usr/local/bin/consul-template

## Configure
RUN mkdir -p $CONSULTEMPLATECONFIGDIR
RUN chmod 755 $CONSULTEMPLATECONFIGDIR
RUN mkdir -p $CONSULTEMPLATEDIR
RUN chmod 755 $CONSULTEMPLATEDIR

## Vault
ARG VAULT_VERSION=1.3.1
ARG VAULTDOWNLOAD=https://releases.hashicorp.com/vault/${VAULT_VERSION}/vault_${VAULT_VERSION}_linux_amd64.zip
ARG VAULTCONFIGDIR=/etc/vault.d
ARG VAULTDIR=/opt/vault

### Download
RUN curl -L $VAULTDOWNLOAD > vault.zip

### Install
RUN unzip vault.zip -d /usr/local/bin
RUN chmod 0755 /usr/local/bin/vault
RUN chown root:root /usr/local/bin/vault

### Configure
RUN mkdir -p $VAULTCONFIGDIR
RUN chmod 755 $VAULTCONFIGDIR
RUN mkdir -p $VAULTDIR
RUN chmod 755 $VAULTDIR

## Nomad
ARG NOMAD_VERSION=0.10.2
ARG NOMADDOWNLOAD=https://releases.hashicorp.com/nomad/${NOMAD_VERSION}/nomad_${NOMAD_VERSION}_linux_amd64.zip
ARG NOMADCONFIGDIR=/etc/nomad.d
ARG NOMADDIR=/opt/nomad

### Download
RUN curl -L $NOMADDOWNLOAD > nomad.zip

### Install
RUN unzip nomad.zip -d /usr/local/bin
RUN chmod 0755 /usr/local/bin/nomad
RUN chown root:root /usr/local/bin/nomad

### Configure
RUN mkdir -p $NOMADCONFIGDIR
RUN chmod 755 $NOMADCONFIGDIR
RUN mkdir -p $NOMADDIR
RUN chmod 755 $NOMADDIR
33 changes: 33 additions & 0 deletions containers/hashistack/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "HashiStack",
"dockerFile": "Dockerfile",

// Use 'settings' to set *default* container specific settings.json values on container create.
// You can edit these settings after create using File > Preferences > Settings > Remote.
"settings": {
"terminal.integrated.shell.linux": "/bin/zsh"
},

// Use 'appPort' to create a container with published ports. If the port isn't working, be sure
// your server accepts connections from all interfaces (0.0.0.0 or '*'), not just localhost.
// 4646: nomad; 8500: consul; 8200: vault;
// "appPort": [4646, 8500, 8200],

// Uncomment the next line to run commands after the container is created.
// "postCreateCommand": "uname -a",

// Uncomment the next line to use Docker from inside the container. See https://aka.ms/vscode-remote/samples/docker-in-docker for details.
"mounts": [ "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind", "type=tmpfs,destination=/tmpfs"],

// Add these to runArgs if you will use a ptrace-based debugger like C++, Go, and Rust
// [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ],
"runArgs": [ "--privileged"],

// Uncomment the next line to have VS Code connect as an existing non-root user in the container.
// On Linux, by default, the container user's UID/GID will be updated to match your local user. See
// https://aka.ms/vscode-remote/containers/non-root for details on adding a non-root user if none exist.
// "remoteUser": "vscode",

// Add the IDs of extensions you want installed when the container is created in the array below.
"extensions": ["wholroyd.hcl"]
}
1 change: 1 addition & 0 deletions containers/hashistack/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
logs/
5 changes: 5 additions & 0 deletions containers/hashistack/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
README.md
test-project
definition-build.json
.vscode
.npmignore
49 changes: 49 additions & 0 deletions containers/hashistack/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# HashiStack

## Summary

*Simple container with Nomad, Consul, and Vault*

| Metadata | Value |
| ---------------------- | ------------------------------------------------------------ |
| *Contributors* | The VS Code Team, [@thoward27](https://github.com/thoward27) |
| *Definition type* | Dockerfile |
| *Published image* | TODO |
| *Languages, platforms* | Any |

## Using this definition with an existing folder

This definition does not require any special steps to use. Just follow these steps:

1. If this is your first time using a development container, please follow the [getting started steps](https://aka.ms/vscode-remote/containers/getting-started) to set up your machine.

2. To use VS Code's copy of this definition:
1. Start VS Code and open your project folder.
2. Press <kbd>F1</kbd> select and **Remote-Containers: Add Development Container Configuration Files...** from the command palette.
3. Select the Ubuntu 18.04 & Git definition.

3. To use latest-and-greatest copy of this definition from the repository:
1. Clone this repository.
2. Copy the contents of `containers/ubuntu-18.04-git/.devcontainer` to the root of your project folder.
3. Start VS Code and open your project folder.

4. After following step 2 or 3, the contents of the `.devcontainer` folder in your project can be adapted to meet your needs.

5. Finally, press <kbd>F1</kbd> and run **Remote-Containers: Reopen Folder in Container** to start using the definition.

## Testing the definition

This definition includes some test code that will help you verify it is working as expected on your system. Follow these steps:

1. If this is your first time using a development container, please follow the [getting started steps](https://aka.ms/vscode-remote/containers/getting-started) to set up your machine.
2. Clone this repository.
3. Start VS Code, press <kbd>F1</kbd>, and select **Remote-Containers: Open Folder in Container...**
4. Select the `containers/ubuntu-18.04-git` folder.
5. Press <kbd>ctrl</kbd>+<kbd>shift</kbd>+<kbd>\`</kbd> and type the following command to verify installation: `apt-get update && apt-get install -y lsb-release && git --version && lsb_release -a`
6. After lsb_release installs, you should see the Git version and details about the version of Linux in the container.

## License

Copyright (c) Microsoft Corporation. All rights reserved.

Licensed under the MIT License. See [LICENSE](https://github.com/Microsoft/vscode-dev-containers/blob/master/LICENSE)
25 changes: 25 additions & 0 deletions containers/hashistack/definition-build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"build": {
"rootDistro": "debian",
"tags": [
"base:${VERSION}-ubuntu-18.04",
"base:${VERSION}-bionic"
]
},
"dependencies": {
"image": "ubuntu:18.04",
"imageLink": "https://hub.docker.com/_/ubuntu",
"manual": [
{
"Component": {
"Type": "git",
"git": {
"Name": "Oh My Zsh!",
"repositoryUrl": "https://github.com/robbyrussell/oh-my-zsh",
"commitHash": "c130aadb6a66aa680a322c08d87ad773316f713d"
}
}
}
]
}
}
56 changes: 56 additions & 0 deletions containers/hashistack/test-project/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash
cd $(dirname "$0")

if [ -z $HOME ]; then
HOME="/root"
fi

FAILED=()

check() {
LABEL=$1
shift
echo -e "\n🧪 Testing $LABEL: $@"
if $@; then
echo "🏆 Passed!"
else
echo "💥 $LABEL check failed."
FAILED+=("$LABEL")
fi
}

checkMultiple() {
PASSED=0
LABEL="$1"
shift; MINIMUMPASSED=$1
shift; EXPRESSION="$1"
while [ "$EXPRESSION" != "" ]; do
if $EXPRESSION; then ((PASSED++)); fi
shift; EXPRESSION=$1
done
check "$LABEL" [ $PASSED -ge $MINIMUMPASSED ]
}

checkExtension() {
checkMultiple "$1" 1 "[ -d ""$HOME/.vscode-server/extensions/$1*"" ]" "[ -d ""$HOME/.vscode-server-insiders/extensions/$1*"" ]" "[ -d ""$HOME/.vscode-test-server/extensions/$1*"" ]"
}

# Actual tests
checkMultiple "vscode-server" 1 "[ -d ""$HOME/.vscode-server/bin"" ]" "[ -d ""$HOME/.vscode-server-insiders/bin"" ]" "[ -d ""$HOME/.vscode-test-server/bin"" ]"
check "non-root-user" "id vscode"
check "/home/vscode" [ -d "/home/vscode" ]
check "sudo" sudo -u vscode echo "sudo works."
check "git" git --version
check "command-line-tools" which top ip lsb_release
check "nomad" nomad -v
check "consul" consul -v
check "vault" vault -v

# Report result
if [ ${#FAILED[@]} -ne 0 ]; then
echo -e "\n💥 Failed tests: ${FAILED[@]}"
exit 1
else
echo -e "\n💯 All passed!"
exit 0
fi
10 changes: 10 additions & 0 deletions containers/hashistack/up.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set -e

mkdir -p logs
consul agent -dev > logs/consul &!
nomad agent -dev > logs/nomad &!
vault server -dev > logs/vault &!

# Export it now and add it to zshrc for later (in case of terminal exit)
export VAULT_ADDR="http://127.0.0.1:8200"
echo 'export VAULT_ADDR="http://127.0.0.1:8200"' >> ~/.zshrc