diff --git a/.devcontainer/README.md b/.devcontainer/README.md index 793f3363cf1..71967768458 100644 --- a/.devcontainer/README.md +++ b/.devcontainer/README.md @@ -68,6 +68,20 @@ bash ../../../scripts/member-local-plan.sh bash ../../../scripts/member-local-plan.sh -r modernisation-platform-sandbox ``` +## Support + +As this is a community supported feature, help is offered on a best endeavour basis. + +If you do need help, please post in [`#devcontainer`](https://moj.enterprise.slack.com/archives/C06DZ4F04JZ) + +## Contribution Guidelines + +- Check that an existing feature doesn't cover what you're trying to add + +- Where possible reuse the existing practices from other features, utilising the shared library `devcontainer-utils` + +- If you are creating a feature, add it to the feature testing matrix in the GitHub Actions workflow and ensure appropiate tests exist + ## Maintainers - [@jacobwoffenden](https://github.com/jacobwoffenden) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 41c4f677096..d8cecf7978a 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -2,7 +2,15 @@ "name": "modernisation-platform-environments", "image": "mcr.microsoft.com/vscode/devcontainers/base:ubuntu", "features": { + "ghcr.io/devcontainers/features/common-utils:2": { + "configureZshAsDefaultShell": true + }, + "./features/src/base": {}, "./features/src/aws": {}, "./features/src/terraform": {} - } + }, + "overrideFeatureInstallOrder": [ + "ghcr.io/devcontainers/features/common-utils", + "./features/src/base" + ] } diff --git a/.devcontainer/features/src/aws/devcontainer-feature.json b/.devcontainer/features/src/aws/devcontainer-feature.json index 7e9e9979d9a..aba8ccbe93f 100644 --- a/.devcontainer/features/src/aws/devcontainer-feature.json +++ b/.devcontainer/features/src/aws/devcontainer-feature.json @@ -16,5 +16,6 @@ "proposals": ["latest"], "default": "latest" } - } + }, + "installsAfter": ["./features/src/base"] } diff --git a/.devcontainer/features/src/aws/install-aws-cli.sh b/.devcontainer/features/src/aws/install-aws-cli.sh index adb70e7ae2b..d9fe00977d1 100644 --- a/.devcontainer/features/src/aws/install-aws-cli.sh +++ b/.devcontainer/features/src/aws/install-aws-cli.sh @@ -1,37 +1,26 @@ #!/usr/bin/env bash -set -euo pipefail +set -e -VERSION=${AWSCLIVERSION:-"latest"} +source /usr/local/bin/devcontainer-utils + +get_system_architecture + +VERSION="${AWSCLIVERSION:-"latest"}" if [[ "${VERSION}" == "latest" ]]; then - ARTEFACT="awscli-exe-linux-$( uname -m ).zip" + ARTEFACT="awscli-exe-linux-$(uname -m).zip" else - ARTEFACT="awscli-exe-linux-$( uname -m )-${VERSION}.zip" + ARTEFACT="awscli-exe-linux-$(uname -m)-${VERSION}.zip" fi -# Install - -apt-get update --yes - -apt-get -y install --no-install-recommends \ - ca-certificates \ - curl \ - unzip +curl --fail-with-body --location "https://awscli.amazonaws.com/${ARTEFACT}" \ + --output "${ARTEFACT}" -curl https://awscli.amazonaws.com/${ARTEFACT} \ - --output ${ARTEFACT} - -unzip ${ARTEFACT} +unzip "${ARTEFACT}" bash ./aws/install -rm --force --recursive aws ${ARTEFACT} - -# Configure - -echo "complete -C '/usr/local/bin/aws_completer' aws" >> /home/vscode/.bashrc - -# Cleanup +rm --recursive --force aws "${ARTEFACT}" -rm --force --recursive /var/lib/apt/lists/* +install --owner=vscode --group=vscode --mode=775 "$(dirname "${0}")"/src/home/vscode/.devcontainer/feature-completion/aws.sh /home/vscode/.devcontainer/feature-completion/aws.sh diff --git a/.devcontainer/features/src/aws/install-aws-sso-cli.sh b/.devcontainer/features/src/aws/install-aws-sso-cli.sh index 12f7bf883e6..e5077fea41d 100644 --- a/.devcontainer/features/src/aws/install-aws-sso-cli.sh +++ b/.devcontainer/features/src/aws/install-aws-sso-cli.sh @@ -1,36 +1,29 @@ #!/usr/bin/env bash -set -euo pipefail +set -e -VERSION=${AWSSSOCLIVERSION:-"latest"} +source /usr/local/bin/devcontainer-utils + +get_system_architecture -case "$( uname -m )" in - x86_64) - export ARCHITECTURE="amd64" ;; - aarch64 | armv8*) - export ARCHITECTURE="arm64" ;; - *) - echo "(!) Architecture $( uname -m ) unsupported"; exit 1 ;; -esac +GITHUB_REPOSITORY="synfinatic/aws-sso-cli" +VERSION=${AWSSSOCLIVERSION:-"latest"} if [[ "${VERSION}" == "latest" ]]; then - VERSION=$(curl --silent "https://api.github.com/repos/synfinatic/aws-sso-cli/releases/latest" | jq -r '.tag_name') - VERSION_STRIP_V=$(echo "${VERSION}" | sed 's/v//') + get_github_latest_tag "${GITHUB_REPOSITORY}" + VERSION="${GITHUB_LATEST_TAG}" + VERSION_STRIP_V="${GITHUB_LATEST_TAG_STRIP_V}" +else + VERSION_STRIP_V="${VERSION#v}" fi -# Install - -curl --location https://github.com/synfinatic/aws-sso-cli/releases/download/${VERSION}/aws-sso-${VERSION_STRIP_V}-linux-${ARCHITECTURE} \ - --output /usr/local/bin/aws-sso - -chmod +x /usr/local/bin/aws-sso - -mkdir --parents /home/vscode/.aws-sso +curl --location https://github.com/${GITHUB_REPOSITORY}/releases/download/${VERSION}/aws-sso-${VERSION_STRIP_V}-linux-${ARCHITECTURE} \ + --output "aws-sso" -cp $( dirname $0 )/src/home/vscode/.aws-sso/config.yaml /home/vscode/.aws-sso/config.yaml +install --owner=vscode --group=vscode --mode=775 aws-sso /usr/local/bin/aws-sso -chown --recursive vscode:vscode /home/vscode/.aws-sso +install --directory --owner=vscode --group=vscode /home/vscode/.aws-sso -# Configure +install --owner=vscode --group=vscode --mode=775 "$(dirname "${0}")"/src/home/vscode/.aws-sso/config.yaml /home/vscode/.aws-sso/config.yaml -echo "export AWS_SSO_FILE_PASSWORD=\"aws_sso_123456789\"" >> /home/vscode/.bashrc +install --owner=vscode --group=vscode --mode=775 "$(dirname "${0}")"/src/home/vscode/.devcontainer/feature-completion/aws-sso.sh /home/vscode/.devcontainer/feature-completion/aws-sso.sh diff --git a/.devcontainer/features/src/aws/install.sh b/.devcontainer/features/src/aws/install.sh index 3d07a4bb2e6..e2fffbdcfa2 100644 --- a/.devcontainer/features/src/aws/install.sh +++ b/.devcontainer/features/src/aws/install.sh @@ -1,5 +1,11 @@ #!/usr/bin/env bash -bash $( dirname $0 )/install-aws-cli.sh +set -e -bash $( dirname $0 )/install-aws-sso-cli.sh +source /usr/local/bin/devcontainer-utils + +logger "info" "Installing AWS CLI (version: ${AWSCLIVERSION})" +bash "$(dirname "${0}")"/install-aws-cli.sh + +logger "info" "Installing AWS SSO CLI (version: ${AWSSSOCLIVERSION})" +bash "$(dirname "${0}")"/install-aws-sso-cli.sh diff --git a/.devcontainer/features/src/aws/src/home/vscode/.devcontainer/feature-completion/aws-sso.sh b/.devcontainer/features/src/aws/src/home/vscode/.devcontainer/feature-completion/aws-sso.sh new file mode 100644 index 00000000000..57befd0fc3b --- /dev/null +++ b/.devcontainer/features/src/aws/src/home/vscode/.devcontainer/feature-completion/aws-sso.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +export AWS_SSO_FILE_PASSWORD="aws_sso_123456789" diff --git a/.devcontainer/features/src/aws/src/home/vscode/.devcontainer/feature-completion/aws.sh b/.devcontainer/features/src/aws/src/home/vscode/.devcontainer/feature-completion/aws.sh new file mode 100644 index 00000000000..95a724522f3 --- /dev/null +++ b/.devcontainer/features/src/aws/src/home/vscode/.devcontainer/feature-completion/aws.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +complete -C '/usr/local/bin/aws_completer' aws diff --git a/.devcontainer/features/src/base/devcontainer-feature.json b/.devcontainer/features/src/base/devcontainer-feature.json new file mode 100644 index 00000000000..6825cb777e3 --- /dev/null +++ b/.devcontainer/features/src/base/devcontainer-feature.json @@ -0,0 +1,12 @@ +{ + "id": "base", + "version": "1.0.0", + "name": "base", + "description": "Base", + "customizations": { + "vscode": { + "extensions": ["GitHub.vscode-pull-request-github", "GitHub.vscode-github-actions", "ms-vsliveshare.vsliveshare"] + } + }, + "installsAfter": ["ghcr.io/devcontainers/features/common-utils"] +} diff --git a/.devcontainer/features/src/base/install.sh b/.devcontainer/features/src/base/install.sh new file mode 100644 index 00000000000..be2b0dc9a4e --- /dev/null +++ b/.devcontainer/features/src/base/install.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +set -e + +source "$(dirname "${0}")"/src/usr/local/bin/devcontainer-utils + +install --owner=vscode --group=vscode --mode=775 "$(dirname "${0}")"/src/usr/local/bin/devcontainer-utils /usr/local/bin/devcontainer-utils + +install --owner=vscode --group=vscode --mode=755 "$(dirname "${0}")"/src/usr/local/etc/vscode-dev-containers/first-run-notice.txt /usr/local/etc/vscode-dev-containers/first-run-notice.txt + +install --owner=vscode --group=vscode --mode=755 "$(dirname "${0}")"/src/home/vscode/.oh-my-zsh/custom/themes/devcontainers.zsh-theme /home/vscode/.oh-my-zsh/custom/themes/devcontainers.zsh-theme + +install --directory --owner=vscode --group=vscode /home/vscode/.devcontainer/feature-completion + +cat <> /home/vscode/.zshrc + +# dev container feature completion scripts +for file in "\${HOME}"/.devcontainer/feature-completion/*.sh; do + source "\${file}" +done +EOF diff --git a/.devcontainer/features/src/base/src/home/vscode/.oh-my-zsh/custom/themes/devcontainers.zsh-theme b/.devcontainer/features/src/base/src/home/vscode/.oh-my-zsh/custom/themes/devcontainers.zsh-theme new file mode 100644 index 00000000000..9329790fc88 --- /dev/null +++ b/.devcontainer/features/src/base/src/home/vscode/.oh-my-zsh/custom/themes/devcontainers.zsh-theme @@ -0,0 +1,51 @@ +# Oh My Zsh! theme - partly inspired by https://github.com/ohmyzsh/ohmyzsh/blob/master/themes/robbyrussell.zsh-theme +# Source: https://github.com/devcontainers/features/blob/main/src/common-utils/scripts/devcontainers.zsh-theme + +__zsh_prompt() { + local prompt_username + if [ ! -z "${GITHUB_USER}" ]; then + prompt_username="@${GITHUB_USER}" + else + prompt_username="%n" + fi + PROMPT="%{$fg[green]%}${prompt_username} %(?:%{$reset_color%}➜ :%{$fg_bold[red]%}➜ )" # User/exit code arrow + PROMPT+='%{$fg_bold[blue]%}%(5~|%-1~/…/%3~|%4~)%{$reset_color%} ' # cwd + PROMPT+='`\ + if [ "$(git config --get devcontainers-theme.hide-status 2>/dev/null)" != 1 ] && [ "$(git config --get codespaces-theme.hide-status 2>/dev/null)" != 1 ]; then \ + export BRANCH=$(git --no-optional-locks symbolic-ref --short HEAD 2>/dev/null || git --no-optional-locks rev-parse --short HEAD 2>/dev/null); \ + if [ "${BRANCH}" != "" ]; then \ + echo -n "%{$fg_bold[cyan]%}(%{$fg_bold[red]%}${BRANCH}" \ + && if [ "$(git config --get devcontainers-theme.show-dirty 2>/dev/null)" = 1 ] && \ + git --no-optional-locks ls-files --error-unmatch -m --directory --no-empty-directory -o --exclude-standard ":/*" > /dev/null 2>&1; then \ + echo -n " %{$fg_bold[yellow]%}✗"; \ + fi \ + && echo -n "%{$fg_bold[cyan]%})%{$reset_color%} "; \ + fi; \ + fi`' + + # Terraform + if command -v terraform &> /dev/null; then + PROMPT+='`\ + terraformVersion=$(terraform -version | grep Terraform | cut -d " " -f 2 | sed "s/v//"); \ + echo -n "[ terraform: %{$fg[blue]%}${terraformVersion}%{$reset_color%} ] " \ + `' + fi + + # AWS SSO + if command -v aws-sso &> /dev/null; then + PROMPT+='`\ + if [[ ${AWS_SSO_PROFILE} == *"development"* || ${AWS_SSO_PROFILE} == *"test"* ]]; then \ + echo -n "[ aws: %{$fg[green]%}${AWS_SSO_PROFILE}@${AWS_DEFAULT_REGION}%{$reset_color%} ] "; \ + elif [[ ${AWS_SSO_PROFILE} == *"preproduction"* ]]; then \ + echo -n "[ aws: %{$fg[yellow]%}${AWS_SSO_PROFILE}@${AWS_DEFAULT_REGION}%{$reset_color%} ] "; \ + elif [[ ${AWS_SSO_PROFILE} == *"production"* ]]; then \ + echo -n "[ aws: %{$fg[red]%}${AWS_SSO_PROFILE}@${AWS_DEFAULT_REGION}%{$reset_color%} ] "; \ + elif [[ ! -z ${AWS_SSO_PROFILE} ]]; then \ + echo -n "[ aws: %{$fg[blue]%}${AWS_SSO_PROFILE}@${AWS_DEFAULT_REGION}%{$reset_color%} ] "; \ + fi`' + fi + + PROMPT+='%{$fg[white]%}$ %{$reset_color%}' + unset -f __zsh_prompt +} +__zsh_prompt diff --git a/.devcontainer/features/src/base/src/usr/local/bin/devcontainer-utils b/.devcontainer/features/src/base/src/usr/local/bin/devcontainer-utils new file mode 100644 index 00000000000..cc08938cf86 --- /dev/null +++ b/.devcontainer/features/src/base/src/usr/local/bin/devcontainer-utils @@ -0,0 +1,75 @@ +#!/usr/bin/env bash + +################################################## +# Environment +################################################## + +export DEBIAN_FRONTEND="noninteractive" + +################################################## +# Function +################################################## + +logger() { + local type="${1}" + local message="${2}" + timestamp=$(date --rfc-3339=seconds) + local timestamp + + case "${type}" in + err | error) + echo "${timestamp} [ERROR] ${message}" + ;; + info | information) + echo "${timestamp} [INFO] ${message}" + ;; + warn | warning) + echo "${timestamp} [WARN] ${message}" + ;; + esac +} + +get_system_architecture() { + systemArchitecture="$(uname -m)" + export systemArchitecture + + case ${systemArchitecture} in + x86_64) + logger "info" "Architecture is x86_64" + export ARCHITECTURE="amd64" + ;; + aarch64 | armv8*) + logger "info" "Architecture is aarch64 or armv8" + export ARCHITECTURE="arm64" + ;; + *) + logger "error" "Architecture ${systemArchitecture} is not supported" + exit 1 + ;; + esac +} + +get_github_latest_tag() { + local repository="${1}" + + repositoryLatestTag="$(curl --silent https://api.github.com/repos/"${repository}"/releases/latest | jq -r '.tag_name')" + export repositoryLatestTag + + repositoryLatestTagStripV=${repositoryLatestTag//v/} + + logger "info" "GitHub latest tag for ${repository} is ${repositoryLatestTag}" + export GITHUB_LATEST_TAG="${repositoryLatestTag}" + export GITHUB_LATEST_TAG_STRIP_V="${repositoryLatestTagStripV}" +} + +apt_install() { + local packages="${1}" + + apt-get update --yes + + apt-get install --yes --no-install-recommends "${packages}" + + apt-get clean + + rm --force --recursive /var/lib/apt/lists/* +} diff --git a/.devcontainer/features/src/base/src/usr/local/etc/vscode-dev-containers/first-run-notice.txt b/.devcontainer/features/src/base/src/usr/local/etc/vscode-dev-containers/first-run-notice.txt new file mode 100644 index 00000000000..f7cbb878554 --- /dev/null +++ b/.devcontainer/features/src/base/src/usr/local/etc/vscode-dev-containers/first-run-notice.txt @@ -0,0 +1,5 @@ +👋 Welcome! You are using the Modernisation Platform Environments dev container image. + +🆘 If you need help or assistance, please post in #devcontainer (https://moj.enterprise.slack.com/archives/C06DZ4F04JZ) + +🔍 To explore VS Code to its fullest, search using the Command Palette (Cmd/Ctrl + Shift + P or F1) diff --git a/.devcontainer/features/src/terraform/devcontainer-feature.json b/.devcontainer/features/src/terraform/devcontainer-feature.json index fdd9d16ebf3..f3d5cdcefec 100644 --- a/.devcontainer/features/src/terraform/devcontainer-feature.json +++ b/.devcontainer/features/src/terraform/devcontainer-feature.json @@ -25,5 +25,6 @@ "editor.defaultFormatter": "hashicorp.terraform" } } - } + }, + "installsAfter": ["./features/src/base"] } diff --git a/.devcontainer/features/src/terraform/install-terraform-switcher.sh b/.devcontainer/features/src/terraform/install-terraform-switcher.sh index eeabde47f45..4054d262c62 100644 --- a/.devcontainer/features/src/terraform/install-terraform-switcher.sh +++ b/.devcontainer/features/src/terraform/install-terraform-switcher.sh @@ -1,53 +1,47 @@ #!/usr/bin/env bash -set -euo pipefail +set -e +source /usr/local/bin/devcontainer-utils + +get_system_architecture + +TERRAFORM_SWITCHER_GITHUB_REPOSITORY="warrensbox/terraform-switcher" TERRAFORM_SWITCHER_VERSION=${TERRAFORMSWITCHERVERSION:-"latest"} + +TERRAFORM_GITHUB_REPOSITORY="hashicorp/terraform" TERRAFORM_VERSION=${TERRAFORMVERSION:-"latest"} -case "$( uname -m )" in - x86_64) - export ARCHITECTURE="amd64" ;; - aarch64 | armv8*) - export ARCHITECTURE="arm64" ;; - *) - echo "(!) Architecture $( uname -m ) unsupported"; exit 1 ;; -esac if [[ "${TERRAFORM_SWITCHER_VERSION}" == "latest" ]]; then - TERRAFORM_SWITCHER_VERSION=$(curl --silent "https://api.github.com/repos/warrensbox/terraform-switcher/releases/latest" | jq -r '.tag_name') - TERRAFORM_SWITCHER_VERSION_STRIP_V=$(echo "${TERRAFORM_SWITCHER_VERSION}" | sed 's/v//g') + get_github_latest_tag "${TERRAFORM_SWITCHER_GITHUB_REPOSITORY}" + TERRAFORM_SWITCHER_VERSION="${GITHUB_LATEST_TAG}" + TERRAFORM_SWITCHER_VERSION_STRIP_V="${GITHUB_LATEST_TAG_STRIP_V}" +else + TERRAFORM_SWITCHER_VERSION_STRIP_V="${TERRAFORM_SWITCHER_VERSION#v}" fi if [[ "${TERRAFORM_VERSION}" == "latest" ]]; then - TERRAFORM_VERSION=$(curl --silent "https://api.github.com/repos/hashicorp/terraform/releases/latest" | jq -r '.tag_name' | sed 's/v//g') + get_github_latest_tag "${TERRAFORM_GITHUB_REPOSITORY}" + TERRAFORM_VERSION="${GITHUB_LATEST_TAG}" + TERRAFORM_VERSION_STRIP_V="${GITHUB_LATEST_TAG_STRIP_V}" +else + TERRAFORM_VERSION_STRIP_V="${TERRAFORM_VERSION#v}" fi -# Install - -curl --location https://github.com/warrensbox/terraform-switcher/releases/download/${TERRAFORM_SWITCHER_VERSION}/terraform-switcher_${TERRAFORM_SWITCHER_VERSION}_linux_${ARCHITECTURE}.tar.gz \ - --output terraform-switcher_${TERRAFORM_SWITCHER_VERSION}_linux_${ARCHITECTURE}.tar.gz - -tar --gzip --extract --file terraform-switcher_${TERRAFORM_SWITCHER_VERSION}_linux_${ARCHITECTURE}.tar.gz - -mv tfswitch /usr/local/bin/tfswitch - -chmod +x /usr/local/bin/tfswitch - -rm --force --recursive CHANGELOG.md LICENSE README.md terraform-switcher_${TERRAFORM_SWITCHER_VERSION}_linux_${ARCHITECTURE}.tar.gz - -# Configure +curl --fail-with-body --location "https://github.com/${TERRAFORM_SWITCHER_GITHUB_REPOSITORY}/releases/download/${TERRAFORM_SWITCHER_VERSION}/terraform-switcher_${TERRAFORM_SWITCHER_VERSION}_linux_${ARCHITECTURE}.tar.gz" \ + --output "terraform-switcher_${TERRAFORM_SWITCHER_VERSION}_linux_${ARCHITECTURE}.tar.gz" -mkdir --parents /home/vscode/.terraform-bin +tar --gzip --extract --file "terraform-switcher_${TERRAFORM_SWITCHER_VERSION}_linux_${ARCHITECTURE}.tar.gz" -chown --recursive vscode:vscode /home/vscode/.terraform-bin +install --owner=vscode --group=vscode --mode=775 tfswitch /usr/local/bin/tfswitch -cp $( dirname $0 )/src/home/vscode/.tfswitch.toml /home/vscode/.tfswitch.toml +rm --force --recursive CHANGELOG.md LICENSE README.md "terraform-switcher_${TERRAFORM_SWITCHER_VERSION}_linux_${ARCHITECTURE}.tar.gz" -chown vscode:vscode /home/vscode/.tfswitch.toml +install --directory --owner=vscode --group=vscode /home/vscode/.terraform-bin -su - vscode --command "tfswitch ${TERRAFORM_VERSION}" +install --owner=vscode --group=vscode --mode=775 "$(dirname "${0}")"/src/home/vscode/.tfswitch.toml /home/vscode/.tfswitch.toml -echo "export PATH=\"\${PATH}:\${HOME}/.terraform-bin\"" >> /home/vscode/.bashrc +install --owner=vscode --group=vscode --mode=775 "$(dirname "${0}")"/src/home/vscode/.devcontainer/feature-completion/terraform.sh /home/vscode/.devcontainer/feature-completion/terraform.sh -echo "complete -o nospace -C \${HOME}/.terraform-bin/terraform terraform" >> /home/vscode/.bashrc +su - vscode --command "tfswitch ${TERRAFORM_VERSION_STRIP_V}" diff --git a/.devcontainer/features/src/terraform/install.sh b/.devcontainer/features/src/terraform/install.sh index b0102894ec5..a17de1b3fd5 100644 --- a/.devcontainer/features/src/terraform/install.sh +++ b/.devcontainer/features/src/terraform/install.sh @@ -1,3 +1,9 @@ #!/usr/bin/env bash -bash $( dirname $0 )/install-terraform-switcher.sh +set -e + +source /usr/local/bin/devcontainer-utils + +logger "info" "Installing Terraform Switcher (version: ${TERRAFORMSWITCHERVERSION})" +logger "info" "Installing Terraform (version: ${TERRAFORMVERSION})" +bash "$(dirname "${0}")"/install-terraform-switcher.sh diff --git a/.devcontainer/features/src/terraform/src/home/vscode/.devcontainer/feature-completion/terraform.sh b/.devcontainer/features/src/terraform/src/home/vscode/.devcontainer/feature-completion/terraform.sh new file mode 100644 index 00000000000..03f408f46f8 --- /dev/null +++ b/.devcontainer/features/src/terraform/src/home/vscode/.devcontainer/feature-completion/terraform.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +export PATH="${PATH}:${HOME}/.terraform-bin" + +complete -o nospace -C ${HOME}/.terraform-bin/terraform terraform diff --git a/.devcontainer/features/test/Containerfile b/.devcontainer/features/test/Containerfile new file mode 100644 index 00000000000..a14867d0b87 --- /dev/null +++ b/.devcontainer/features/test/Containerfile @@ -0,0 +1,5 @@ +FROM mcr.microsoft.com/devcontainers/base:ubuntu + +COPY .devcontainer/features/src/base/src/usr/local/bin/devcontainer-utils /usr/local/bin/devcontainer-utils + +RUN install --directory --owner=vscode --group=vscode /home/vscode/.devcontainer/feature-completion diff --git a/.devcontainer/features/test/aws/test.sh b/.devcontainer/features/test/aws/test.sh index a1c552f8c56..8fa5a42d0d2 100644 --- a/.devcontainer/features/test/aws/test.sh +++ b/.devcontainer/features/test/aws/test.sh @@ -5,6 +5,10 @@ set -e source dev-container-features-test-lib check "aws version" aws --version +check "aws completions existence" stat /home/vscode/.devcontainer/feature-completion/aws.sh + check "aws-sso version" aws-sso version +check "aws-sso completions existence" stat /home/vscode/.devcontainer/feature-completion/aws-sso.sh +check "aws-sso configuration existence" stat /home/vscode/.aws-sso/config.yaml reportResults diff --git a/.devcontainer/features/test/base/test.sh b/.devcontainer/features/test/base/test.sh new file mode 100644 index 00000000000..e07a01f2527 --- /dev/null +++ b/.devcontainer/features/test/base/test.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +set -e + +source dev-container-features-test-lib + +check "devcontainer-utils file existence" stat /usr/local/bin/devcontainer-utils +check "first-run-notice.txt file existence" stat /usr/local/etc/vscode-dev-containers/first-run-notice.txt +check "devcontainer feature completion directory existence" stat /home/vscode/.devcontainer/feature-completion +check "dev container theme file existence" stat /home/vscode/.oh-my-zsh/custom/themes/devcontainers.zsh-theme +check "feature completion zshrc snippet existence" grep -q "dev container feature completion scripts" /home/vscode/.zshrc + +reportResults diff --git a/.devcontainer/features/test/terraform/test.sh b/.devcontainer/features/test/terraform/test.sh index ab6742054c8..5aeda20f551 100644 --- a/.devcontainer/features/test/terraform/test.sh +++ b/.devcontainer/features/test/terraform/test.sh @@ -6,5 +6,7 @@ source dev-container-features-test-lib check "tfswitch version" tfswitch --version check "terraform version" /home/vscode/.terraform-bin/terraform -version +check "terraform completions existence" stat /home/vscode/.devcontainer/feature-completion/terraform.sh +check "tfswitch configuration existence" stat /home/vscode/.tfswitch.toml reportResults diff --git a/.github/workflows/devcontainer.yml b/.github/workflows/devcontainer.yml new file mode 100644 index 00000000000..48cd9faa436 --- /dev/null +++ b/.github/workflows/devcontainer.yml @@ -0,0 +1,72 @@ +--- +name: Development Container + +on: + pull_request: + branches: + - main + paths: + - .github/workflows/devcontainer.yml + - .devcontainer/** + +permissions: {} + +env: + DEVCONTAINER_CLI_VERSION: latest + +jobs: + build: + name: Build + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - name: Checkout + id: checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + + - name: Install devcontainers/cli + id: install_devcontainer_cli + run: npm install -g @devcontainers/cli@${{ env.DEVCONTAINER_CLI_VERSION }} + + - name: devcontainer build + id: devcontainer_build + run: devcontainer build --workspace-folder . + + test-features: + name: Test Features + runs-on: ubuntu-latest + permissions: + contents: read + strategy: + fail-fast: false + matrix: + feature: + - base + - aws + - terraform + steps: + - name: Checkout + id: checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + + - name: Install devcontainers/cli + id: install_devcontainer_cli + run: npm install -g @devcontainers/cli@${{ env.DEVCONTAINER_CLI_VERSION }} + + - name: Build Test Image + id: build_test_image + uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5.1.0 + with: + file: .devcontainer/features/test/Containerfile + load: true + tags: devcontainer + + - name: Testing ${{ matrix.feature }} + id: test_feature + run: | + devcontainer features test \ + --skip-scenarios \ + --project-folder .devcontainer/features \ + --features ${{ matrix.feature }} \ + --base-image devcontainer diff --git a/terraform/environments/cdpt-chaps/database.tf b/terraform/environments/cdpt-chaps/database.tf index c1d41bf0d50..de75b22636b 100644 --- a/terraform/environments/cdpt-chaps/database.tf +++ b/terraform/environments/cdpt-chaps/database.tf @@ -58,15 +58,6 @@ resource "aws_security_group" "db" { } } -resource "aws_security_group_rule" "allow_ec2_to_rds" { - type = "ingress" - from_port = 1433 - to_port = 1433 - protocol = "tcp" - source_security_group_id = aws_security_group.cluster_ec2.id - security_group_id = aws_security_group.db.id -} - data "aws_secretsmanager_secret" "db_password" { name = aws_secretsmanager_secret.chaps_secret.name } diff --git a/terraform/environments/digital-prison-reporting/modules/dms_s3_v2/iam.tf b/terraform/environments/digital-prison-reporting/modules/dms_s3_v2/iam.tf new file mode 100644 index 00000000000..a3633132976 --- /dev/null +++ b/terraform/environments/digital-prison-reporting/modules/dms_s3_v2/iam.tf @@ -0,0 +1,138 @@ +#DMS S3 Endpoint role +resource "aws_iam_role" "dms-s3-role" { + count = var.setup_dms_endpoints && var.setup_dms_iam ? 1 : 0 + + name = "${var.project_id}-dms-${var.short_name}-s3-endpoint-role" + path = "/" + + assume_role_policy = <