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

Edge release #2

Merged
merged 8 commits into from
Jul 9, 2024
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
26 changes: 26 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM mcr.microsoft.com/devcontainers/base:alpine-3.20

RUN <<EOF
set -ex
apk update
apk add --no-cache \
asio-dev \
autoconf \
build-base \
binutils \
cmake \
curl \
file \
gcc \
g++ \
git \
libgcc \
libtool \
linux-headers \
make \
musl-dev \
ninja \
tar \
unzip \
wget
EOF
53 changes: 53 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/alpine
{
"name": "Alpine",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"build": {
"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": "uname -a",
// Configure tool-specific properties.
// "customizations": {},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
"customizations": {
"vscode": {
"settings": {
"shellformat.path": "/usr/local/bin/shfmt"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"editorconfig.editorconfig",
"ms-vscode.cpptools",
"huizhou.githd",
"letmaik.git-tree-compare",
"GitHub.vscode-pull-request-github",
"twxs.cmake",
"ms-vscode.cmake-tools"
]
}
},
"mounts": [
"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind", // mount the Docker socket
"source=/etc/localtime,target=/etc/localtime,type=bind,readonly", // mount localtime
"source=/dev,target=/dev,type=bind" // Required for recognizing new USB devices
// "source=${localWorkspaceFolder}/.devcontainer/.bash_aliases,target=/home/vscode/.bash_aliases,type=bind",
// "source=brewblox-usb-proxy-extensions,target=/home/vscode/.vscode-server/extensions,type=volume"
],
"runArgs": [
"--rm",
"--cap-add=SYS_PTRACE", // required for attaching a C++ debugger
"--security-opt",
"seccomp=unconfined",
"--privileged",
"--network=host"
],
"remoteUser": "vscode",
"features": {}
}
22 changes: 2 additions & 20 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,17 @@ on:
workflow_dispatch: {}

env:
DOCKER_IMAGE: ghcr.io/you/your-package
DOCKER_IMAGE: ghcr.io/brewblox/brewblox-usb-proxy

jobs:
build:
if: false
if: github.repository_owner == 'BrewBlox'
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Get image metadata
id: meta
Expand All @@ -37,21 +34,6 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry wheel
poetry install

- name: Test
run: |
poetry run pytest
poetry run flake8

- name: Build Python dist
run: |
poetry run invoke dist

- name: Build Docker image
uses: docker/build-push-action@v5
with:
Expand Down
89 changes: 77 additions & 12 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,79 @@
{
"python.defaultInterpreterPath": ".venv/bin/python",
"python.terminal.activateEnvInCurrentTerminal": true,
"python.terminal.activateEnvironment": true,
"python.testing.pytestArgs": [
"."
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.languageServer": "Pylance",
"[python]": {
"editor.defaultFormatter": "ms-python.autopep8"
"files.associations": {
"iostream": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"charconv": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"codecvt": "cpp",
"compare": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"map": "cpp",
"set": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"format": "cpp",
"fstream": "cpp",
"future": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"semaphore": "cpp",
"span": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"typeinfo": "cpp",
"variant": "cpp",
"csignal": "cpp",
"any": "cpp",
"complex": "cpp",
"coroutine": "cpp",
"list": "cpp",
"source_location": "cpp",
"shared_mutex": "cpp",
"cinttypes": "cpp",
"typeindex": "cpp"
}
}
}
16 changes: 16 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "cmake",
"label": "CMake: build",
"command": "build",
"targets": [
"all"
],
"group": "build",
"problemMatcher": [],
"detail": "CMake template build task"
}
]
}
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.20)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
set(CMAKE_RULE_MESSAGES OFF)

cmake_policy(SET CMP0076 NEW)

# Declare the project
project(usb_proxy)
add_executable(usb_proxy src/main.cpp)

# Get system variables
get_filename_component(APP_ROOT
${CMAKE_CURRENT_LIST_DIR}/
ABSOLUTE
)

# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -ggdb")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -ggdb")
71 changes: 46 additions & 25 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,41 +1,62 @@
FROM python:3.11-bookworm as base
FROM alpine:3.20 as base
WORKDIR /app

ENV PIP_EXTRA_INDEX_URL=https://www.piwheels.org/simple
ENV PIP_FIND_LINKS=/wheeley
ENV VENV=/app/.venv
ENV PATH="$VENV/bin:$PATH"
RUN <<EOF
set -ex
apk update
apk add --no-cache \
asio-dev \
autoconf \
build-base \
binutils \
cmake \
curl \
file \
gcc \
g++ \
git \
libgcc \
libtool \
linux-headers \
make \
musl-dev \
ninja \
tar \
unzip \
wget
EOF

COPY ./dist /app/dist
COPY CMakeLists.txt /app/
COPY src/* /app/src/

RUN <<EOF
set -ex

mkdir /wheeley
python3 -m venv $VENV
pip3 install --upgrade pip wheel setuptools
pip3 wheel --wheel-dir=/wheeley -r /app/dist/requirements.txt
pip3 wheel --wheel-dir=/wheeley /app/dist/*.tar.gz
mkdir build/
cd build
cmake -G Ninja -S ..
ninja
EOF

FROM python:3.11-slim-bookworm
FROM alpine:3.20
EXPOSE 5000
WORKDIR /app

ENV PIP_FIND_LINKS=/wheeley
ENV VENV=/app/.venv
ENV PATH="$VENV/bin:$PATH"

COPY --from=base /wheeley /wheeley
COPY ./entrypoint.sh ./entrypoint.sh
COPY --from=base /app/build/usb_proxy /app/usb_proxy

RUN <<EOF
set -ex
apk update
apk add --no-cache \
socat \
libstdc++

rm -rf /var/cache/apk/*

python3 -m venv $VENV
pip3 install --no-index your_package
pip3 freeze
rm -rf /wheeley
chmod +x /app/usb_proxy
EOF

# Discovery terminates expired proxies as a side effect.
# By periodically discovering the non-existent "health" device,
# we both confirm that the service is healthy, and trigger this side effect.
HEALTHCHECK CMD wget --quiet --spider --tries=1 http://127.0.0.1:5000/usb-proxy/discover/health || exit 1

ENTRYPOINT ["bash", "./entrypoint.sh"]
ENTRYPOINT ["/app/usb_proxy"]
Loading