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

49 - codespaces/ #50

Merged
merged 14 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 16 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM mcr.microsoft.com/devcontainers/miniconda:0-3

# Copy environment.yml (if found) to a temp location so we update the environment. Also
# copy "noop.txt" so the COPY instruction does not fail if no environment.yml exists.
COPY ../codespaces/demoVE.yml* ../codespaces/noop.txt /tmp/conda-tmp/
RUN if [ -f "/tmp/conda-tmp/demoVE.yml" ]; then umask 0002 && /opt/conda/bin/conda env create -f /tmp/conda-tmp/demoVE.yml; fi \
&& rm -rf /tmp/conda-tmp

# [Optional] Uncomment to install a different version of Python than the default
# RUN conda install -y python=3.6 \
# && pip install --no-cache-dir pipx \
# && pipx reinstall-all

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>
44 changes: 44 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/miniconda
{
"name": "Miniconda (Python 3)",
"build": {
"context": "..",
"dockerfile": "Dockerfile"
},

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "python --version",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "conda init",

// Configure tool-specific properties.
"customizations": {
"vscode": {
"settings": {
"python.defaultInterpreterPath": "/opt/conda/envs/demoVE"
},
"extensions": [
// "ms-python.python",
// "donjayamanne.python-extension-pack",
// "ms-toolsai.jupyter",
// "GitHub.codespaces",
// "ms-azuretools.vscode-docker",
// "UserName.vscode-markdownlint"
]
}
}
}
49 changes: 49 additions & 0 deletions codespaces/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Codespaces

## New to codespaces?
* [Start here](https://docs.github.com/en/codespaces). Learn the core concepts and how to get started.
* [Quickstart for GitHub Codespaces](https://docs.github.com/en/codespaces/getting-started/quickstart).

## Create codespaces
1. Open your repository and go to `Code`>`Codespaces`
2. Select branch
3. Create codespace on `branch-name`. #This will take 3-ish minutes to prebuild container

The creation of codespace make use of
* [Dockerfile](../.devcontainer/Dockerfile)
* [devcontainer.json](../.devcontainer/devcontainer.json)
* [demoVE.yaml](demoVE.yml)
* [noop.txt](noop.txt)


## (First time) Predefined dev container configuration
1. Access the Visual Studio Code Command Palette (Shift+Command+P / Ctrl+Shift+P), then start typing "add dev".
Click Codespaces: Add Dev Container Configuration Files.
2. Create a new config file
3. Select container conf template: Miniconda (Python3)
4. Select additional feature `Nothing`

Creates: `docker_funny_name_ID` https://github.com/codespaces/`docker_funny_name_ID`
You can check in the terminal these commands: `conda info` and `conda env list`

## (Already created) Running demo scripts
* Activate `docker_funny_name_ID` https://github.com/codespaces/`docker_funny_name_ID`
* Open notebook
* Select Kernel (top right icon)
* `Install enable suggested extensions Python + Jupyter`
* Python environment
* demoVE (Python VERSION) /opt/conda/envs/demoVE/bin/python
* Run notebook
* Stop running container (bottom left menu)
* Maybe go https://github.com/codespaces/ to delete it


## References
https://www.sckaiser.com/blog/2023/01/30/conda-codespaces.html
https://github.com/crazy4pi314/conda-devcontainer-demo
https://blog.shibayan.jp/entry/20220309/1646754054
https://www.youtube.com/watch?v=RIchFX_gYb0
https://github.com/microsoft/AI-For-Beginners/blob/main/.devcontainer/Dockerfile
* Prebuild configuration: https://github.com/mxochicale/code/settings/codespaces
* https://docs.github.com/en/codespaces/setting-up-your-project-for-codespaces/adding-a-dev-container-configuration/introduction-to-dev-containers#using-a-predefined-dev-container-configuration

Binary file added codespaces/can-cats-eat-avocado-as-a-snack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
89 changes: 89 additions & 0 deletions codespaces/demo.ipynb

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions codespaces/demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

# https://blog.shibayan.jp/entry/20220309/1646754054

import cv2
print(cv2.__version__)

source_image = cv2.imread('shibayan.png')
gray_image = cv2.cvtColor(source_image, cv2.COLOR_BGR2GRAY)
cv2.imwrite('output.png', gray_image)
11 changes: 11 additions & 0 deletions codespaces/demoVE.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: demoVE
channels:
- conda-forge
- default
dependencies:
- python==3.11.*
- pip
- pip:
- opencv-python-headless
- ipykernel # required for jupyter notebook in VS Code
- matplotlib
Loading