Skip to content

Commit

Permalink
chore: configure a devcontainer
Browse files Browse the repository at this point in the history
Configure a devcontainer for the repository
  • Loading branch information
ferrarimarco committed Jan 23, 2025
1 parent b144d6d commit f58ece1
Show file tree
Hide file tree
Showing 8 changed files with 297 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
FROM hashicorp/terraform:1.5.7 AS terraform
FROM koalaman/shellcheck:v0.10.0 AS shellcheck
FROM mvdan/shfmt:v3.10.0 AS shfmt

FROM python:3.13-bookworm AS python-builder

SHELL ["/bin/bash", "-o", "errexit", "-o", "nounset", "-o", "pipefail", "-c"]

RUN mkdir -p /venv

COPY dependencies/requirements.txt /venv/requirements.txt

RUN python -m venv /venv \
&& . /venv/bin/activate \
&& pip install -r /venv/requirements.txt

FROM node:23.3-bookworm AS npm-builder

SHELL ["/bin/bash", "-o", "errexit", "-o", "nounset", "-o", "pipefail", "-c"]

COPY dependencies/package.json dependencies/package-lock.json /
RUN npm audit \
&& npm install --strict-peer-deps \
&& npm cache clean --force

FROM python:3.13-bookworm AS devcontainer

SHELL ["/bin/bash", "-o", "errexit", "-o", "nounset", "-o", "pipefail", "-c"]

COPY --from=shellcheck /bin/shellcheck /usr/bin/
COPY --from=shfmt /bin/shfmt /usr/bin/
COPY --from=terraform /bin/terraform /usr/bin/
COPY --from=python-builder /venv /venv
COPY --from=npm-builder /node_modules /node_modules

ENV PATH="${PATH}:/venv/bin"
ENV PATH="${PATH}:/node_modules/.bin"

# Quick smoke test
RUN \
shellcheck --version \
&& shfmt --version \
&& CHECKPOINT_DISABLE="not needed for version checks" terraform --version
28 changes: 28 additions & 0 deletions .devcontainer/dependencies/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .devcontainer/dependencies/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "accelerated-platforms-devcontainer",
"dependencies": {
"prettier": "^3.4.2"
}
}
1 change: 1 addition & 0 deletions .devcontainer/dependencies/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
black==24.10.0
79 changes: 79 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"$schema": "https://raw.githubusercontent.com/devcontainers/spec/main/schemas/devContainer.schema.json",
"name": "Cloud Solutions devcontainer",
"build": {
"dockerfile": "Dockerfile"
},
"customizations": {
"vscode": {
"settings": {
"editor.formatOnSave": true,
"editor.formatOnSaveMode": "file",
"editor.rulers": [80],
"editor.wordWrap": "off",
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"prettier.resolveGlobalModules": true,
"redhat.telemetry.enabled": false,
"telemetry.telemetryLevel": "off",
"[css]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[markdown]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.wordWrap": "off"
},
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"[scss]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[shellscript]": {
"editor.defaultFormatter": "mkhl.shfmt"
},
"[terraform]": {
"editor.defaultFormatter": "hashicorp.terraform"
},
"[terraform-vars]": {
"editor.defaultFormatter": "hashicorp.terraform"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[yaml]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
},
"extensions": [
"EditorConfig.EditorConfig",
"esbenp.prettier-vscode",
"HashiCorp.terraform",
"mads-hartmann.bash-ide-vscode",
"mkhl.shfmt",
"ms-azuretools.vscode-docker",
"ms-python.black-formatter",
"timonwong.shellcheck"
]
}
},
"runArgs": ["--rm"]
}
51 changes: 51 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
version: 2
updates:
- package-ecosystem: "devcontainers"
commit-message:
prefix: "deps"
directory: "/"
schedule:
interval: weekly
open-pull-requests-limit: 100
- directory: "/"
commit-message:
prefix: "deps"
package-ecosystem: "github-actions"
schedule:
interval: "daily"
groups:
ci-cd-tooling:
applies-to: version-updates
patterns:
- actions/*
- docker/*
- github/*
- hashicorp/*
- psf/black
- directories:
- /.devcontainer
commit-message:
prefix: "deps"
package-ecosystem: "docker"
schedule:
interval: "daily"
open-pull-requests-limit: 100
groups:
ci-cd-tooling:
applies-to: version-updates
patterns:
- python
- package-ecosystem: "npm"
commit-message:
prefix: "deps"
directories:
- /.devcontainer/dependencies
schedule:
interval: "weekly"
open-pull-requests-limit: 100
groups:
ci-cd-tooling:
applies-to: version-updates
patterns:
- "prettier*"
86 changes: 86 additions & 0 deletions .github/workflows/build-container-images.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
name: Build and push container images

env:
CONTAINER_IMAGE_REGISTRY: ghcr.io

permissions:
contents: read

on:
push:
paths:
- ".github/workflows/build-container-images.yaml"
- ".devcontainer/**"
pull_request:
paths:
- ".github/workflows/build-container-images.yaml"
- ".devcontainer/**"

jobs:
build-container-images:
concurrency:
# Ref: https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
# github.head_ref: head_ref or source branch of the pull request
# github.ref: ref of the branch that triggered the workflow
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}-${{ github.event_name }}-${{ matrix.container-images.name }}
cancel-in-progress: true
env:
CONTAINER_IMAGE_ID: "${{ github.repository }}-${{ matrix.container-images.name }}"
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Validate Docker build configuration
shell: bash
run: |
DOCKER_BUILD_COMMAND=(docker buildx build --check)
if [[ -n "${{ matrix.container-images.build-contexts }}" ]]; then
# TODO: add more parsing logic if there's more than one build context
# xargs trims the string
DOCKER_BUILD_COMMAND+=(--build-context="$(xargs echo "${{ matrix.container-images.build-contexts }}")")
fi
DOCKER_BUILD_COMMAND+=("${{ matrix.container-images.context-directory }}")
echo "Running: ${DOCKER_BUILD_COMMAND[*]}"
"${DOCKER_BUILD_COMMAND[@]}"
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/[email protected]
with:
images: |
${{ env.CONTAINER_IMAGE_REGISTRY }}/${{ env.CONTAINER_IMAGE_ID }}
labels: |
org.opencontainers.image.title=accelerated-platforms-${{ matrix.container-images.name }}
org.opencontainers.image.description=${{ matrix.container-images.name }} container image
tags: |
type=edge,enable={{is_default_branch}}
type=ref,event=branch,enable={{is_default_branch}}
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}.{{patch}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Build the ${{ matrix.container-images.name }} container image
uses: docker/build-push-action@v6
with:
build-contexts: ${{ matrix.container-images.build-contexts }}
cache-from: type=gha
cache-to: type=gha,mode=max
context: ${{ matrix.container-images.context-directory }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
strategy:
matrix:
container-images:
- name: devcontainer
context-directory: .devcontainer
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ monitoring-dashboard-samples/
# Test
test/log/*.log
test/scripts/environment_files/*

# Node
node_modules

0 comments on commit f58ece1

Please sign in to comment.