From c77f71638336e52ad1a66bcad232cb05cf39714c Mon Sep 17 00:00:00 2001 From: drifter089 Date: Thu, 10 Oct 2024 17:39:50 +0700 Subject: [PATCH] adding dev container config --- .devcontainer/devcontainer.json | 9 +++++++ .devcontainer/setup.sh | 6 +++++ .devcontainer/welcome-message.txt | 13 +++++++++ .github/.devcontainer/devcontainer.json | 33 +++++++++++++++++++++++ .github/workflows/devcontainer.yaml | 36 +++++++++++++++++++++++++ Dockerfile | 18 +++++++++++++ Dockerfile.solved | 26 ++++++++++++++++++ config.tutorial.yaml | 1 + 8 files changed, 142 insertions(+) create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/setup.sh create mode 100644 .devcontainer/welcome-message.txt create mode 100644 .github/.devcontainer/devcontainer.json create mode 100644 .github/workflows/devcontainer.yaml create mode 100644 Dockerfile create mode 100644 Dockerfile.solved diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..81e1605d9 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,9 @@ +// For format details, see https://aka.ms/devcontainer.json. +{ + "name": "pypsa earth dev", + "image": "ghcr.io/drifter089/pypsa-earth:latest", + "workspaceMount": "source=${localWorkspaceFolder},target=/workspaces,type=bind,consistency=cached", + "initializeCommand": "docker pull ghcr.io/drifter089/pypsa-earth:latest", + "workspaceFolder": "/workspaces", + "postAttachCommand": "bash .devcontainer/setup.sh" +} diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh new file mode 100644 index 000000000..e2fc1a3e8 --- /dev/null +++ b/.devcontainer/setup.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +# mv ../pypsa-eur/* ./ +# echo 'solved tutorial files are copied to workspace' + +cat .devcontainer/welcome-message.txt \ No newline at end of file diff --git a/.devcontainer/welcome-message.txt b/.devcontainer/welcome-message.txt new file mode 100644 index 000000000..a0c311068 --- /dev/null +++ b/.devcontainer/welcome-message.txt @@ -0,0 +1,13 @@ + + +👋 Welcome to pypsa-eur contribution in a dev container! + Works in VS Code, or in docker using the devcontainer cli + +See https://github.com/drifter089/pypsa-eur/blob/master/README.md for guidance on debugging and contributing to pypsa-eur + + +For details about dev containers see https://containers.dev + +The configuration for the dev container is in the .github/.devcontainer folder. + +🔍 To explore VS Code to its fullest, search using the Command Palette (Cmd/Ctrl + Shift + P or F1).+ \ No newline at end of file diff --git a/.github/.devcontainer/devcontainer.json b/.github/.devcontainer/devcontainer.json new file mode 100644 index 000000000..fda35213c --- /dev/null +++ b/.github/.devcontainer/devcontainer.json @@ -0,0 +1,33 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu +{ + "name": "pypsa earth dev", + "build": { + "dockerfile": "../../Dockerfile" + }, + + "features": { + "ghcr.io/devcontainers-contrib/features/bash-command:1": {}, + "ghcr.io/eliises/devcontainer-features/bash-profile:1": {} + }, + "customizations": { + "vscode": { + "terminal.integrated.profiles.linux": { + "bash": { + "path": "/bin/bash" + } + }, + "extensions": [ + "ms-python.python", + "ms-python.vscode-pylance", + "ms-azuretools.vscode-docker", + "ms-toolsai.jupyter", + "zainchen.json", + "tomoki1207.pdf", + "grapecity.gc-excelviewer" + ] + } + }, + + "postCreateCommand": "python -m pip install --upgrade debugpy" +} diff --git a/.github/workflows/devcontainer.yaml b/.github/workflows/devcontainer.yaml new file mode 100644 index 000000000..ec48a223e --- /dev/null +++ b/.github/workflows/devcontainer.yaml @@ -0,0 +1,36 @@ +name: Dev Container Build and Push Image + +on: + workflow_dispatch: + push: + branches: + - "main" + tags: + - "v*.*.*" + pull_request: + branches: [main] + + +jobs: + build-and-push: + runs-on: ubuntu-latest + steps: + - + name: Checkout + id: checkout + uses: actions/checkout@v1 + - + name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.REGISTRY_TOKEN }} + - + name: Pre-build dev container image + uses: devcontainers/ci@v0.2 + with: + subFolder: .github + imageName: ghcr.io/${{ github.repository }} + cacheFrom: ghcr.io/${{ github.repository }} + push: always \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..6c8c64296 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM condaforge/mambaforge + +RUN conda update -n base conda +RUN conda install -n base conda-libmamba-solver +RUN conda config --set solver libmamba + +WORKDIR /pypsa-earth + +COPY ./envs ./envs + +RUN conda env create --file envs/environment.yaml + +RUN rm -r envs + +RUN echo "source activate pypsa-earth" > ~/.bashrc +ENV PATH /opt/conda/envs/pypsa-earth/bin:$PATH + +ENTRYPOINT ["tail", "-f", "/dev/null"] diff --git a/Dockerfile.solved b/Dockerfile.solved new file mode 100644 index 000000000..f832c7a2b --- /dev/null +++ b/Dockerfile.solved @@ -0,0 +1,26 @@ +FROM condaforge/mambaforge + +RUN conda update -n base conda +RUN conda install -n base conda-libmamba-solver +RUN conda config --set solver libmamba + +RUN apt-get update && apt-get install -y git + +WORKDIR /pypsa-earth + +COPY . . + +RUN conda env create --file envs/environment.yaml + +RUN echo "source activate pypsa-earth" > ~/.bashrc +ENV PATH /opt/conda/envs/pypsa-earth/bin:$PATH + +RUN /bin/bash -c "source activate pypsa-earth && snakemake -j 1 solve_all_networks" + +RUN git ls-files -z | xargs -0 rm + +RUN find . -type d -empty -delete + +RUN rm -rf scripts config data .snakemake .git + +ENTRYPOINT ["tail", "-f", "/dev/null"] diff --git a/config.tutorial.yaml b/config.tutorial.yaml index 0c98bb152..02ef557aa 100644 --- a/config.tutorial.yaml +++ b/config.tutorial.yaml @@ -9,6 +9,7 @@ tutorial: true countries: ["NG", "BJ"] enable: + retrieve_databundle: true build_natura_raster: true progress_bar: false