diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000..343af45d90 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +.git +.mypy_cache diff --git a/.github/workflows/devcontainer-docker-image.yml b/.github/workflows/devcontainer-docker-image.yml new file mode 100644 index 0000000000..d3826efed8 --- /dev/null +++ b/.github/workflows/devcontainer-docker-image.yml @@ -0,0 +1,54 @@ +name: devcontainer-docker-image + +on: + workflow_dispatch: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }}-devcontainer # pymc-devs/pymc-devcontainer + +jobs: + build-container: + runs-on: ubuntu-latest + + # Set permissions for GitHub token + # + permissions: + contents: read + packages: write + + steps: + - name: Checkout source + uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b + + - name: Setup Docker buildx + uses: docker/setup-buildx-action@dc7b9719a96d48369863986a06765841d7ea23f6 + + - name: Prepare metadata + id: meta + uses: docker/metadata-action@69f6fc9d46f2f8bf0d5491e4aabe0bb8c6a4678a + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=sha,enable=true,prefix=git- + type=raw,value=latest + + - name: Log into registry ${{ env.REGISTRY }} + uses: docker/login-action@49ed152c8eca782a232dede0303416e8f356c37b + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push Docker image + id: docker_build + uses: docker/build-push-action@e551b19e49efd4e98792db7592c17c09b89db8d8 + with: + context: . + file: scripts/dev.Dockerfile + platforms: linux/amd64 # ,linux/arm64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest + cache-to: type=inline diff --git a/.gitpod.yml b/.gitpod.yml index 234e7584a1..a09276d016 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -1,20 +1,45 @@ -image: ghcr.io/conda/conda-ci:main-linux-python3.9 +image: ghcr.io/maresb/pymc-devcontainer:latest tasks: - name: initialize init: | + # General devcontainer initialization, e.g. pre-commit + _dev-init.sh + + # Create an empty object for .vscode/settings.json if the file doesn't exist mkdir -p .vscode - echo '{"python.defaultInterpreterPath": "/workspace/pymc/env/bin/python"}' > .vscode/settings.json - conda init bash && source ~/.bashrc - conda env update -f conda-envs/environment-dev.yml -p /workspace/pymc/env - conda activate /workspace/pymc/env + [ -f .vscode/settings.json ] || echo "{}" > .vscode/settings.json + + # Add vscode settings + jq ' + .["python.defaultInterpreterPath"] = "/opt/conda/bin/python" + ' .vscode/settings.json | sponge .vscode/settings.json + jq ' + .["terminal.integrated.defaultProfile.linux"] = "bash" + ' .vscode/settings.json | sponge .vscode/settings.json + jq ' + .["git.autofetch"] = true + ' .vscode/settings.json | sponge .vscode/settings.json + + # Install dependencies + sudo chown "$(id -u):$(id -g)" /opt/conda/conda-meta/history + micromamba install --yes --name base --file conda-envs/environment-dev.yml + + # Install PyMC pip install -e . + command: | - conda init bash && echo "conda activate /workspace/pymc/env" >> ~/.bashrc && source ~/.bashrc + # Reinitialize devcontainer for good measure + _dev-init.sh + + # Install the pre-commit hooks in the background if not already installed + pre-commit install --install-hooks vscode: extensions: - eamodio.gitlens - ms-python.python + - ms-pyright.pyright + - donjayamanne.githistory github: prebuilds: diff --git a/scripts/dev.Dockerfile b/scripts/dev.Dockerfile new file mode 100644 index 0000000000..624149455d --- /dev/null +++ b/scripts/dev.Dockerfile @@ -0,0 +1,21 @@ +FROM ghcr.io/mamba-org/micromamba-devcontainer:git-5185ae9 + +COPY --chown=${MAMBA_USER}:${MAMBA_USER} conda-envs/environment-dev.yml /tmp/environment-dev.yml +RUN : \ + && micromamba install --yes --name base --file /tmp/environment-dev.yml \ + && micromamba clean --all --yes \ + && rm /tmp/environment-dev.yml \ + && sudo chmod -R a+rwx /opt/conda \ +; + +ARG MAMBA_DOCKERFILE_ACTIVATE=1 + +COPY --chown=${MAMBA_USER}:${MAMBA_USER} .pre-commit-config.yaml /fake-repo/.pre-commit-config.yaml +RUN : \ + && sudo mkdir --mode=777 /opt/.pre-commit-cache-prebuilt \ + && cd /fake-repo \ + && git init \ + && PRE_COMMIT_HOME=/opt/.pre-commit-cache-prebuilt pre-commit install-hooks \ + && sudo rm -rf /fake-repo \ + && sudo chmod -R a+rwx /opt/.pre-commit-cache-prebuilt \ +;