Skip to content

Commit 1c26cac

Browse files
author
Alan Christie
committed
feat: Add devcontainer to simplify configuration
1 parent 42ac90a commit 1c26cac

10 files changed

Lines changed: 256 additions & 67 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM mcr.microsoft.com/devcontainers/python:1-3.13-bullseye
2+
3+
# The platform (CPU architecture)
4+
# if not provided by a build-arg we take a default (ARM)
5+
ARG PLATFORM=amd64
6+
ENV PLATFORM=$PLATFORM
7+
8+
# Install our main Python requirements
9+
# and kubectl
10+
ARG KUBECTL_VERSION=1.32.8
11+
COPY requirements.txt /tmp
12+
RUN pip install -r /tmp/requirements.txt \
13+
&& rm /tmp/requirements.txt \
14+
&& curl -LO "https://dl.k8s.io/release/v${KUBECTL_VERSION}/bin/linux/${PLATFORM}/kubectl" \
15+
&& install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

.devcontainer/devcontainer.json

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/python
3+
{
4+
"name": "Ansible Infrastructure Python 3.13",
5+
"build": {
6+
"dockerfile": "Dockerfile",
7+
// Args is one of arm64 or amd64
8+
"args": {
9+
"PLATFORM": "${localEnv:PLATFORM:arm64}"
10+
}
11+
},
12+
"features": {
13+
"ghcr.io/devcontainers/features/docker-in-docker:2": {
14+
"moby": true,
15+
"azureDnsAutoDetection": true,
16+
"installDockerBuildx": true,
17+
"installDockerComposeSwitch": true,
18+
"version": "latest",
19+
"dockerDashComposeVersion": "v2"
20+
},
21+
"ghcr.io/devcontainers/features/git:1": {
22+
"ppa": true,
23+
"version": "os-provided"
24+
}
25+
},
26+
// We mount bash history in an attempt to preserver history
27+
// between container restarts
28+
// (see https://code.visualstudio.com/remote/advancedcontainers/persist-bash-history)
29+
//
30+
// The user will also need a ~/k8s-config directory (kubernetes config files)
31+
// as well as a ~/.kube directory
32+
"mounts": [
33+
"source=${localEnv:HOME}/.gitconfig,target=/home/vscode/.gitconfig,type=bind,consistency=cached",
34+
"source=${localEnv:HOME}/k8s-config,target=/k8s-config,type=bind,consistency=cached",
35+
"source=${localEnv:HOME}/.kube,target=/home/vscode/.kube,type=bind,consistency=cached",
36+
"source=projectname-bashhistory,target=/commandhistory,type=volume"
37+
],
38+
"customizations": {
39+
"vscode": {
40+
"extensions": [
41+
"codezombiech.gitignore",
42+
"donjayamanne.githistory",
43+
"donjayamanne.git-extension-pack",
44+
"eamodio.gitlens",
45+
"github.vscode-github-actions",
46+
"ms-kubernetes-tools.vscode-kubernetes-tools",
47+
"ms-python.vscode-pylance",
48+
"sourcery.sourcery",
49+
"streetsidesoftware.code-spell-checker",
50+
"trond-snekvik.simple-rst",
51+
"vivaxy.vscode-conventional-commits",
52+
"yzhang.markdown-all-in-one"
53+
]
54+
}
55+
},
56+
"postCreateCommand": {
57+
"Install Pre-Commit": "pre-commit install -t commit-msg -t pre-commit",
58+
"Fix Volume Permissions": "sudo chown -R $(whoami): /commandhistory"
59+
},
60+
"forwardPorts": []
61+
}

.devcontainer/requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Requirements file for the dev-container
2+
ansible == 12.0.0
3+
kubernetes == 31.0.0
4+
poetry == 2.2.1
5+
pre-commit == 4.3.0

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ repos:
88

99
# Conventional Commit message checker (commitizen)
1010
- repo: https://github.com/commitizen-tools/commitizen
11-
rev: v3.12.0
11+
rev: v4.9.1
1212
hooks:
1313
- id: commitizen
1414
stages:
@@ -19,7 +19,7 @@ repos:
1919

2020
# Standard pre-commit rules
2121
- repo: https://github.com/pre-commit/pre-commit-hooks
22-
rev: v4.5.0
22+
rev: v6.0.0
2323
hooks:
2424
- id: check-case-conflict
2525
- id: check-docstring-first
@@ -36,7 +36,7 @@ repos:
3636
- --markdown-linebreak-ext=md
3737

3838
- repo: https://github.com/adrienverge/yamllint
39-
rev: v1.33.0
39+
rev: v1.37.1
4040
hooks:
4141
- id: yamllint
4242

@@ -51,6 +51,6 @@ repos:
5151
# - ansible-core>=2.16.0
5252

5353
- repo: https://github.com/IamTheFij/ansible-pre-commit
54-
rev: v1.0.0
54+
rev: v1.0.1
5555
hooks:
5656
- id: encryption-check

doc/getting-started.rst

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ Getting Started
44

55
Prerequisites
66
=============
7-
87
Before starting a basic understanding or experience with the following will
98
be beneficial: -
109

@@ -13,8 +12,23 @@ be beneficial: -
1312
* `Ansible Galaxy`_
1413
* `Ansible Vault`_
1514

16-
Working environment
17-
===================
15+
Working environment (VSCode)
16+
============================
17+
If you are familiar with VisualStudio Code the easiest way to get started is to use
18+
our built-in **development container**. It provides you with a pre-configured set of
19+
tools, including ``kubectl`` and ``pre-commit`` pre-configured.
20+
21+
You will need to have two directories in your HOME directory: ``.kube`` (the default
22+
location for kubeconfig files) and ``k8-config``, our own directory where we tend to
23+
store all our installation config files, each in a separate kubeconfig file.
24+
25+
.. warning::
26+
Make sure you have these directories before you start your devcontainer,
27+
otherwise the container build will fail.
28+
29+
Working environment (DIY)
30+
=========================
31+
If you do not use VisualStudio the following instuctions should help you get started.
1832

1933
Ideally you'll start from a Poetry environment::
2034

@@ -35,7 +49,6 @@ And can then check the current diction fo the repository with::
3549

3650
Cluster (Kubernetes) pre-requisites
3751
===================================
38-
3952
Your Kubernetes cluster will need: -
4053

4154
1. A **StorageClass** for the infrastructure database (postgres).
@@ -62,17 +75,16 @@ Your Kubernetes cluster will need: -
6275

6376
Cluster credentials
6477
===================
65-
6678
You will also need a copy of your **kubeconfig** file and will need to set the
6779
``KUBECONFIG`` environment variable to point to your copy. You can safely place
6880
the config in the root of a clone of this repository as the file
6981
``kubeconfig`` as this is part of the project ignore set::
7082

71-
$ export KUBECONFIG=./kubeconfig
83+
$ export KUBECONFIG=~/k8s-config/my-config
7284

7385
Plays run from within AWX benefit from the automatic injection of Kubernetes
7486
variables. Once installed our AWX will inject the following environment
75-
cat variables: -
87+
variables: -
7688

7789
- ``K8S_AUTH_HOST``
7890
- ``K8S_AUTH_API_KEY``
@@ -100,7 +112,6 @@ configuring via the environment for some of the Roles to properly function::
100112
export AWS_ACCESS_KEY_ID=xxxxxxxxxxxx
101113
export AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxx
102114

103-
104115
The permissions of the AWS user will depend on what you intend to deploy.
105116
Typically these will be something like: -
106117

host_vars/localhost.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22

33
ansible_connection: local
4+
ansible_python_interpreter: python
45

56
# Install core?
67
core_state: present

0 commit comments

Comments
 (0)