Skip to content

Commit

Permalink
Merge pull request #371 from odin-detector/containers
Browse files Browse the repository at this point in the history
Add developer and deployment containers infrastructure
  • Loading branch information
GDYendell authored Dec 13, 2024
2 parents 1f4fa48 + 8ba29cc commit bbad1ac
Show file tree
Hide file tree
Showing 12 changed files with 378 additions and 2 deletions.
57 changes: 57 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// For format details, see https://containers.dev/implementors/json_reference/
{
"name": "odin-data devcontainer",
"build": {
"dockerfile": "../Dockerfile",
"context": "..",
"target": "developer"
},
"remoteEnv": {
// Allow X11 apps to run inside the container
"DISPLAY": "${localEnv:DISPLAY}"
},
"customizations": {
"vscode": {
"settings": {
"python.defaultInterpreterPath": "/venv/bin/python",
// Disable auto port forwarding when using --net=host
"remote.autoForwardPorts": false
},
"extensions": [
"ms-python.python",
"github.vscode-github-actions",
"tamasfe.even-better-toml",
"redhat.vscode-yaml",
"ryanluker.vscode-coverage-gutters",
"charliermarsh.ruff",
"ms-vscode.cmake-tools",
"ms-vscode.cpptools"
]
}
},
// For docker, VSCODE_REMOTE_USER must be set to your username. You will run with
// full sudo rights. For podman, it should be left blank. You will run as root
// inside, but host mounts will be owned by your user id and permissions will be
// limited to those of the user on the host.
"remoteUser": "${localEnv:VSCODE_REMOTE_USER}",
"features": {
// Some default things like git config
"ghcr.io/devcontainers/features/common-utils:2": {
"upgradePackages": false
}
},
"runArgs": [
// Allow the container to access the host X11 display and ports on localhost
"--net=host",
// Make sure SELinux does not disable with access to host filesystems like /tmp
"--security-opt=label=disable"
],
// Mount the parent as /workspaces so we can add peer projects to the workspace
"workspaceMount": "source=${localWorkspaceFolder}/..,target=/workspaces,type=bind",
"mounts": [
// Mount /dev/shm for odin-data applications to use
"source=/dev/shm,target=/dev/shm,type=bind"
],
// After the container is created, install the python project in editable form
"postCreateCommand": "pip install $([ -f dev-requirements.txt ] && echo '-c dev-requirements.txt') -e './python[dev]'"
}
6 changes: 6 additions & 0 deletions .devcontainer/initializeCommand
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# custom initialization goes here - runs outside of the dev container
# just before the container is launched but after the container is created

echo "devcontainerID ${1}"
28 changes: 28 additions & 0 deletions .devcontainer/postCreateCommand
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# Custom initialization goes here if needed.
# Runs inside the dev container after the container is created

################################################################################
# When using docker we will not be root inside the container
# You may wish to change ownership of files you want the user to modify
################################################################################

# if [[ $USER != "root" ]] ; then
# # make sure the non-root user can build iocs and (mounted in) support modules
# # sudo chown -R ${USER}:${USER} add_folders_here_if needed
# fi

################################################################################
# Shell customizations for Generic IOC devcontainers
################################################################################

# pick a zsh theme that does not cause completion corruption in zsh vscode terminals
sed -i $HOME/.zshrc -e 's/ZSH_THEME="devcontainers"/ZSH_THEME="dst"/'

# allow personalization of all devcontainers in this subdirectory
# by placing a .devcontainer_rc file in the workspace root
if [[ -f /workspaces/.devcontainer_rc ]] ; then
source /workspaces/.devcontainer_rc
fi

18 changes: 18 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# avoid blowing the cache over build files

.dockerignore

external
*build*
*prefix*
*.pyc
tools/python/venv
venv*
tools/python/.coverage
*.egg-info


tools/python/build
tools/python/dist

docs/build/
118 changes: 118 additions & 0 deletions .github/workflows/container.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
name: Container CI

# Only tags are pushed to the registry because of rules in the steps
on:
push:
pull_request:

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

env:
TAG: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0 # All history

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Log in to GitHub Docker Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

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

- name: Build image
uses: docker/build-push-action@v4
with:
context: .
file: Dockerfile
target: runtime
push: false
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache

- name: Create tags for developer image
id: meta-developer
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}-developer
tags: |
type=ref,event=tag
type=raw,value=latest
- name: Push developer image
if: github.ref_type == 'tag'
uses: docker/build-push-action@v4
with:
context: .
file: Dockerfile
target: developer
tags: ${{ steps.meta-developer.outputs.tags }}
labels: ${{ steps.meta-developer.outputs.labels }}
push: ${{ github.event_name != 'pull_request' }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache

- name: Create tags for build image
id: meta-build
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}-build
tags: |
type=ref,event=tag
type=raw,value=latest
- name: Push build image
if: github.ref_type == 'tag'
uses: docker/build-push-action@v4
with:
context: .
file: Dockerfile
target: build
tags: ${{ steps.meta-build.outputs.tags }}
labels: ${{ steps.meta-build.outputs.labels }}
push: ${{ github.event_name != 'pull_request' }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache

- name: Create tags for runtime image
id: meta-runtime
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}-runtime
tags: |
type=ref,event=tag
type=raw,value=latest
- name: Push runtime image
if: github.ref_type == 'tag'
uses: docker/build-push-action@v4
with:
context: .
file: Dockerfile
target: runtime
tags: ${{ steps.meta-runtime.outputs.tags }}
labels: ${{ steps.meta-runtime.outputs.labels }}
push: ${{ github.event_name != 'pull_request' }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/external
/*build*
/*prefix/
/vscode_prefix
*.pyc
/tools/python/venv/
/.settings
Expand All @@ -15,7 +16,6 @@ tools/python/.coverage

.idea/
cmake-build*/
.vscode/

tools/imagej/plugins/*
!tools/imagej/plugins/Odin-Data/
Expand Down
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"ms-vscode-remote.remote-containers",
]
}
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Meta Writer",
"type": "debugpy",
"request": "launch",
"module": "odin_data.meta_writer.meta_writer_app",
"args": [
"--log-level=DEBUG"
]
},
]
}
18 changes: 18 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"cmake.generator": "Unix Makefiles",
"cmake.sourceDirectory": "${workspaceFolder}/cpp",
"cmake.buildDirectory": "${workspaceFolder}/vscode_build",
"cmake.installPrefix": "/odin",
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
},
"files.insertFinalNewline": true,
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true,
"editor.rulers": [88]
},
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
}
27 changes: 27 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "Tests, lint and docs",
"command": "tox -p",
"options": {
"cwd": "${workspaceRoot}"
},
"problemMatcher": [],
},
{
"label": "Run Dummy Decoder System Test",
"type": "shell",
"options": {
"env": {
"INSTALL_PREFIX": "${workspaceFolder}/vscode_prefix"
},
},
"command": "${workspaceFolder}/vscode_prefix/bin/odinDataTest --json=${workspaceFolder}/vscode_prefix/test_config/dummyUDP.json",
"problemMatcher": [],
}
]
}
Loading

0 comments on commit bbad1ac

Please sign in to comment.