Skip to content

Commit

Permalink
Update container deployment
Browse files Browse the repository at this point in the history
Update vscode CMake config to install into /odin
Add publish of build container. This is used as a base for detector
developer containers
 on where they have the full dev environment but also have odin-data
installed in /odin
 to build against.
Add python3.11 install
Add hdf5filters install for compression libs
  • Loading branch information
GDYendell committed Dec 4, 2024
1 parent ee40c5e commit ac419d2
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 100 deletions.
54 changes: 27 additions & 27 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,50 @@
"context": "..",
"target": "developer"
},
"features": {
// add quality of life features for developers including git config integration
// note this is slow for the odin-data container - leaving out for now
"ghcr.io/devcontainers/features/common-utils:2": {
// don't upgrade to make this similar to the runtime container
"upgradePackages": false
}
"remoteEnv": {
// Allow X11 apps to run inside the container
"DISPLAY": "${localEnv:DISPLAY}"
},
// IMPORTANT for this devcontainer to work with docker VSCODE_REMOTE_USER must be
// set to vscode. You will run as vscode with full sudo rights.
// For podman it should be left blank. You will run as root but host mounts
// will be owned by your user.
"remoteUser": "${localEnv:VSCODE_REMOTE_USER}",
"customizations": {
"vscode": {
// Add the IDs of extensions you want installed when the container is created.
"settings": {
"python.defaultInterpreterPath": "/venv/bin/python"
},
"extensions": [
"ms-python.vscode-pylance",
"ms-python.python",
"github.vscode-github-actions",
"tamasfe.even-better-toml",
"redhat.vscode-yaml",
"ryanluker.vscode-coverage-gutters",
"epicsdeb.vscode-epics",
"charliermarsh.ruff",
"ms-vscode.cmake-tools",
"ms-vscode.cpptools"
]
}
},
// You can place any outside of the container before-launch commands here
"initializeCommand": "bash .devcontainer/initializeCommand ${devcontainerId}",
// One time global setup commands inside the container
"postCreateCommand": "bash .devcontainer/postCreateCommand ${devcontainerId}",
// 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 EPICS CA
// Allow the container to access the host X11 display and ports on localhost
"--net=host",
// Make sure SELinux does not disable write access to host filesystems like tmp
// Make sure SELinux does not disable with access to host filesystems like /tmp
"--security-opt=label=disable"
],
// Mount the parent of the project folder so we can access peer projects
// Mount the parent as /workspaces so we can add peer projects to the workspace
"workspaceMount": "source=${localWorkspaceFolder}/..,target=/workspaces,type=bind",
// mount in other useful files from the host
"mounts": [
// add extra mounts below
// "source=${localWorkspaceFolder},target=/odin-data,type=bind"
// 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]'"
}
73 changes: 46 additions & 27 deletions .github/workflows/container.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
name: Container CI

# Only tags are pushed to the registry because of rules in the steps
on:
push:
# Build for main, tags and PRs
# Builds from PRs are not pushed to the registry because of rules in the steps
branches:
# push these changes to the branch 'docker' for container publishing
- docker
tags:
- "*"
pull_request:

jobs:
Expand All @@ -18,6 +12,9 @@ jobs:
contents: read
packages: write

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

steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -40,60 +37,82 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=ref,event=branch
type=ref,event=tag
type=raw,value=latest
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1

- name: Docker meta config build
id: meta-build
uses: docker/metadata-action@v4
- 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=branch
type=ref,event=tag
type=raw,value=latest
- name: Docker build build image
- 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: Docker meta config runtime
- name: Create tags for runtime image
id: meta-runtime
uses: docker/metadata-action@v4
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}-runtime
tags: |
type=ref,event=branch
type=ref,event=tag
type=raw,value=latest
- name: Docker build runtime image
- name: Push runtime image
if: github.ref_type == 'tag'
uses: docker/build-push-action@v4
with:
context: .
file: Dockerfile
target: runtime
push: ${{ github.event_name != 'pull_request' }}
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
6 changes: 1 addition & 5 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{
"recommendations": [
"ms-vscode-remote.remote-containers",
"twxs.cmake",
"ms-vscode.cpptools",
"ms-python.python",
"ms-python.vscode-pylance",
]
}
}
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
"version": "0.2.0",
"configurations": [
{
"name": "MetaWriter",
"type": "python",
"name": "Meta Writer",
"type": "debugpy",
"request": "launch",
"module": "odin_data.meta_writer.meta_writer_app",
"args": [
"--log-level=DEBUG"
]
},
]
}
}
28 changes: 13 additions & 15 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,20 +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": "${workspaceFolder}/vscode_prefix",
"cmake.configureArgs": [
// all dependencies from system inside the container
],
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"editor.formatOnSave": true,
"cmake.installPrefix": "/odin",
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
},
"files.insertFinalNewline": true,
"[python]": {
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
},
"editor.defaultFormatter": "ms-python.python",
"editor.rulers": [
88
]
}
}
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true,
"editor.rulers": [88]
},
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
}
15 changes: 12 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
{
// 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",
Expand All @@ -15,4 +24,4 @@
"problemMatcher": [],
}
]
}
}
51 changes: 31 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
# shared setup stage ###########################################################
# Shared setup stage ###########################################################
FROM ubuntu:24.04 AS common

ENV PATH=/odin/bin:/venv/bin:$PATH

# get fundamental packages
# Get fundamental packages
RUN apt-get update -y && \
apt-get install --no-install-recommends -y curl \
tar ca-certificates software-properties-common && \
apt-get -y clean all
# get zellij

# Get zellij
RUN curl -L https://github.com/zellij-org/zellij/releases/download/v0.40.1/zellij-x86_64-unknown-linux-musl.tar.gz -o zellij.tar.gz && \
tar -xvf zellij.tar.gz -C /usr/bin && \
rm zellij.tar.gz
# setup zellij
RUN mkdir -p ~/.config/zellij && \
zellij setup --dump-config > ~/.config/zellij/config.kdl

# developer stage for devcontainer #############################################
# Developer stage for devcontainer #############################################
FROM common AS developer

# system depenedencies
# System dependencies
RUN add-apt-repository -y ppa:deadsnakes/ppa && \
apt-get update -y && apt-get install -y --no-install-recommends \
# General build
Expand All @@ -31,40 +31,51 @@ RUN add-apt-repository -y ppa:deadsnakes/ppa && \
# tidy up
apt-get -y clean all

# python dependencies
# Python dependencies
RUN python3.11 -m ensurepip && \
python3.11 -m venv /venv && \
python -m pip install --upgrade pip && \
python -m pip install git+https://github.com/odin-detector/[email protected]
python -m pip install git+https://github.com/odin-detector/odin-control

# Install hdf5filters from source
RUN git clone https://github.com/DiamondLightSource/hdf5filters.git && cd hdf5filters && \
mkdir -p cmake-build && cd cmake-build && \
cmake -DCMAKE_INSTALL_PREFIX=/odin -DCMAKE_BUILD_TYPE=Release -DUSE_AVX2=ON .. && \
make install && \
rm -rf hdf5filters

# build stage - throwaway stage for runtime assets #############################
# Build stage - throwaway stage for runtime assets #############################
FROM developer AS build

# fetch the source
WORKDIR /tmp/odin-data
# Copy in project
WORKDIR /odin/odin-data
COPY . .

# C++
RUN mkdir /odin && \
mkdir -p build && cd build && \
RUN mkdir -p build && cd build && \
cmake -DCMAKE_INSTALL_PREFIX=/odin ../cpp && \
make -j8 VERBOSE=1 && \
make install

# Python
RUN python -m pip install /tmp/odin-data/python[meta_writer]
RUN python -m pip install /odin/odin-data/python[meta_writer]

# Runtime stage ################################################################
FROM common as runtime
FROM common AS runtime

# runtime system dependencies
RUN apt-get update -y && apt-get install -y --no-install-recommends \
# odin-data C++ dependencies
libblosc-dev libboost-all-dev libhdf5-dev liblog4cxx-dev libpcap-dev libczmq-dev && \
# tidy up
# Runtime system dependencies
RUN add-apt-repository -y ppa:deadsnakes/ppa && \
apt-get update -y && apt-get install -y --no-install-recommends \
# C++ dependencies
libblosc-dev libboost-all-dev libhdf5-dev liblog4cxx-dev libpcap-dev libczmq-dev \
# Python dependencies
python3.11 && \
# Tidy up
apt-get -y clean all

COPY --from=build /odin /odin
COPY --from=build /venv /venv

RUN rm -rf /odin/odin-data /odin/odin-control

WORKDIR /odin
Loading

0 comments on commit ac419d2

Please sign in to comment.