Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Devcontainer support #358

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
91 changes: 91 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
FROM python:3.11-slim-bookworm AS devcontainer

WORKDIR /tmp/buildingmotif

RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends\
git \
curl \
ca-certificates \
xz-utils \
openssh-client \
; \
rm -rf /var/lib/apt/lists/*

# Install NREL root certs. So that vscode server can install
COPY .devcontainer/certs /usr/local/share/ca-certificates
RUN update-ca-certificates

ENV NODE_EXTRA_CA_CERTS=/etc/ssl/certs/ca-certificates.crt

# Install Java (this is the smallest JRE I could find)
ARG JAVA_VERSION=21.0.5+11
ARG JAVA_TYPE=jre
ARG JAVA_DIR=/usr/lib/jvm/jdk-${JAVA_VERSION}-${JAVA_TYPE}
RUN case "$(uname -m)" in \
x86_64) ARCH='x64';; \
aarch64) ARCH='aarch64';; \
*) echo "unsupported architecture"; exit 1 ;; \
esac; \
set -eux; \
JAVA_VERSION_=$(echo ${JAVA_VERSION} | sed 's/+/_/g'); \
mkdir -p ${JAVA_DIR}; \
curl -fsL https://github.com/adoptium/temurin21-binaries/releases/download/jdk-${JAVA_VERSION}/OpenJDK21U-${JAVA_TYPE}_${ARCH}_linux_hotspot_${JAVA_VERSION_}.tar.gz | tar xz -C /usr/lib/jvm/; \
ln -s ${JAVA_DIR}/bin/java /usr/bin/java

# Install Docker (CLI only, as the engine is running on the host)
ARG DOCKER_VERSION=27.3.1
ARG BUILDX_VERSION=0.17.1
RUN case "$(uname -m)" in \
x86_64) ARCH='amd64';; \
aarch64) ARCH='arm64';; \
*) echo "unsupported architecture"; exit 1 ;; \
esac; \
set -eux; \
curl -fsSL -o docker-ce-cli.deb https://download.docker.com/linux/debian/dists/bookworm/pool/stable/${ARCH}/docker-ce-cli_${DOCKER_VERSION}-1~debian.12~bookworm_${ARCH}.deb; \
curl -fsSL -o docker-buildx-plugin.deb https://download.docker.com/linux/debian/dists/bookworm/pool/stable/${ARCH}/docker-buildx-plugin_${BUILDX_VERSION}-1~debian.12~bookworm_${ARCH}.deb; \
dpkg -i docker-ce-cli.deb; \
dpkg -i docker-buildx-plugin.deb; \
rm docker-ce-cli.deb docker-buildx-plugin.deb

# Install NodeJS
ARG NODE_VERSION=20.18.0
RUN case "$(uname -m)" in \
x86_64) ARCH='x64';; \
aarch64) ARCH='arm64';; \
*) echo "unsupported architecture"; exit 1 ;; \
esac; \
curl -fsL https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${ARCH}.tar.xz | tar xJ -C /usr/local --strip-components=1

# Setup poetry without virtual environments so that dependencies persist to a mounted BuildingMOTIF workspace
ENV POETRY_VIRTUALENVS_IN_PROJECT=FALSE
ENV POETRY_VIRTUALENVS_CREATE=FALSE
RUN set -eux; \
python -m pip install poetry; \
rm -rf ~/.cache/pip

COPY pyproject.toml pyproject.toml
COPY poetry.lock poetry.lock

RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
gcc \
libc6-dev \
libpq-dev \
; \
poetry install --no-root --all-extras; \
apt-mark auto gcc libc6-dev libpq-dev; \
apt-mark manual libpq5; \
apt-get autoremove -y; \
rm -rf /var/lib/apt/lists/*; \
rm -rf ~/.cache/pypoetry/cache ~/.cache/pypoetry/artifacts

# Setup angular and install dependencies globally
RUN set -eux; \
npm install -g @angular/cli@17; \
echo "source <(ng completion script)" > /root/.bashrc; \
rm -rf ~/.npm/_cacache

WORKDIR /workspaces/BuildingMOTIF
29 changes: 29 additions & 0 deletions .devcontainer/certs/nrel_root_ca.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-----BEGIN CERTIFICATE-----
MIIFCTCCAvGgAwIBAgIQFAtDE3Je/69GK7W99f7tJDANBgkqhkiG9w0BAQsFADAX
MRUwEwYDVQQDEwxOUkVMIFJvb3QgQ0EwHhcNMTUxMjE2MTgxNDI0WhcNMzUxMjE2
MTgyNDIwWjAXMRUwEwYDVQQDEwxOUkVMIFJvb3QgQ0EwggIiMA0GCSqGSIb3DQEB
AQUAA4ICDwAwggIKAoICAQCpYVD8CSy828twIE28C9kPkdHKWj3YZ2nosggnddNV
94QLR5avIQcg9BZZVd2vca4jVj1IFm25ejkpVCMfKk+VQ0MDRBHLylYZ1U9Q3I3p
GcsAz2xYPaO187I7pLBx65X48MKwK88Rnv1tAyAU/+0OMwfsJhTwt/seGsUgBR+O
BnxE7U/RZzu058JnosB3HjFkZSnvKu9HYGbtHat2LBDYXToTWEnCJOLToZECzjgy
TLaAax36eyBrZS3uCyOJ2eZlq84sLHBPlicsHyoEoLaOseP+VFXTVUT5zApcjKD+
nKV4CkW6DfowxktHvGrEa9Yg0GPPJY5AKO5AewGf7sCto/Ek9G8b2/thttk0cI8v
kmISrz08Rak4LxyfH5+8aLQHBYXmB8mZLGHQeOR4n4ETNrMASGUv/Lr9O3diTzs4
UCXjRh181ACsYFMLrvsZtQsrbW2MZVyvxUkrnazDFAj7mdsU3MWUhOwOpCe1umWO
Qct12skcXic75zsk8klMIRsxWGd3pUO3Sn7jkhbq6JDP+4iUvNzPIsvNMu59Dxeh
ykTV3590OaVALoTJXnwza1YQDV/mAUjxVWa6GozqikbdcQ0XszoUuNMcy/jMPzyV
hPlKrtUsoewerksAPopKiAUgsV7KTkbWwKpQ2430W4J3eI5wCSRygxFFvhEvhk69
kQIDAQABo1EwTzALBgNVHQ8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4E
FgQUJnsHde+RBaZSxeTQbJ/2JUo5YOgwEAYJKwYBBAGCNxUBBAMCAQAwDQYJKoZI
hvcNAQELBQADggIBAAtRrbzhhuv96CwOw8mi36xuF1zi2JA6Xj67PsVJPlQM6JdW
t00rzlza311PXB30KvN3nzQxzTvPl15UixOxKR6cySetpaMnAUaxGgX9+4uZr4jv
A1DHl3FBfIAFkZIymZAxCLwvkldQJBfOv9kFNWUo9vuFeZEo6QssElOeOv6uSAJW
XAdW3zT4rqV+0rrcJF/S8fBm2JW5Y3yJYu1kfoIYkcE5TYLWm4lvgmsSEgJaRw8B
ySA2j5lhcyyL32IJ/zU87K1LO6/2DJqcnsNX/otSg+xL3QeVaVAHcZHHR2HqCO5F
2KGriIMLecYW5hLj0mLlXNEU2taO8Lz4CN+ckmMUj0SOZCMwbllrMuoLrNzEaIJO
BHiTopwToxlvt8YBF0QO43hGTJBR10VFQ2EY0AdrH2a/e69Dwl5WqFJ6OOxspK/U
FI6QbqR60ujI01/t3C5AAKW2KvG+AjK4stmskIkFYJHukBLAU0vEWg+0BK8LLiHO
KFIigWMJUCp+xMestk6/niGFUUAfDWZ0/g/Lkyp3B2xgE2uW661tx77Pbop/+6JO
54JPZPeUznBfAoBNypIJRG9ghSne/KK0mTREiUe2wVtsFyD8rdrdVilSjFxi7jcV
LOpuNtdI4fP/hzRs7rvIq1Yl7yxI2HBw6ybPDnaIl6M7eNsQhqDE4xUDO6n+
-----END CERTIFICATE-----
26 changes: 26 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
// Uncomment this and commend "image" out for local devcontainer building.
TShapinsky marked this conversation as resolved.
Show resolved Hide resolved
// "build": {
// "dockerfile": "Dockerfile",
// "context": "../"
// },
"image": "ghcr.io/nrel/buildingmotif/devcontainer:ts-devcontainers",
"runArgs": ["--net=host"], // Use host network for webapp (which only listens for localhost by default)
"mounts": [
"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" // Allow usage of host docker within container
],
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-azuretools.vscode-docker",
"ms-python.vscode-pylance",
"ms-python.debugpy",
"ms-toolsai.jupyter"
],
"settings": {
"jupyter.kernels.excludePythonEnvironments":["/workspaces/BuildingMOTIF/.venv"] //Mask existing virtual environments from being picked up in container
}
}
}
}
56 changes: 56 additions & 0 deletions .github/workflows/devcontainer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Build for Development
TShapinsky marked this conversation as resolved.
Show resolved Hide resolved

on:
push:
branches:
- 'ts/devcontainers'


env:
REGISTRY: ghcr.io

jobs:
build-image:
name: Build image
runs-on: ubuntu-latest
# timeout-minutes: 40
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log into container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker meta
uses: docker/metadata-action@v5
id: meta
with:
images: |
${{ env.REGISTRY }}/${{ github.repository }}/devcontainer
tags: |
type=ref,event=branch
type=sha
type=edge

- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: .devcontainer/Dockerfile
push: true
target: devcontainer
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.output.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
Loading