Skip to content

Commit

Permalink
Create build, dev, daemon docker compose workflows for easy developme…
Browse files Browse the repository at this point in the history
…nt on any system (with docker)

VSCode development container

attempt to not mess with file endings

Allow running with debugging as module

Add docker workflow documentation start and VSCode remote container config

enable docker container development environment

split vscode image into seperate image

only start VSCode container for dev env
  • Loading branch information
nznobody committed Oct 13, 2021
1 parent eb3a2db commit cd247a1
Show file tree
Hide file tree
Showing 11 changed files with 233 additions and 18 deletions.
54 changes: 54 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.191.1/containers/docker-existing-docker-compose
// If you want to run as a non-root user in the container, see .devcontainer/docker-compose.yml.
{
"name": "Existing Docker Compose (Extend)",

// Update the 'dockerComposeFile' list if you have more compose files or use different names.
// The .devcontainer/docker-compose.yml file contains any overrides you need/want to make.
"dockerComposeFile": [
"../docker-compose.yml",
"docker-compose.yml"
],

// The 'service' property is the name of the service for the container that VS Code should
// use. Update this value and .devcontainer/docker-compose.yml to the real service name.
"service": "vscode",

"runServices": ["vscode"],

// The optional 'workspaceFolder' property is the path VS Code should open by default when
// connected. This is typically a file mount in .devcontainer/docker-compose.yml
"workspaceFolder": "/workspace",

// Set *default* container specific settings.json values on container create.
"settings": {},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-python.python",
"lextudio.restructuredtext",
"trond-snekvik.simple-rst",
"ms-azuretools.vscode-docker"
],
"portsAttributes": {
"80": {
"label": "HTTP_API"
}
},

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

// Uncomment the next line if you want start specific services in your Docker Compose config.
// "runServices": [],

// Uncomment the next line if you want to keep your containers running after VS Code shuts down.
// "shutdownAction": "none",

// Uncomment the next line to run commands after the container is created - for example installing curl.
"postCreateCommand": "sudo python3 setup.py develop && sudo chmod o+rw /var/run/docker.sock",

// Uncomment to connect as a non-root user if you've added one. See https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
38 changes: 38 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: '3.7'
services:
# Update this to the name of the service you want to work with in your docker-compose.yml file
vscode:
# If you want add a non-root user to your Dockerfile, you can use the "remoteUser"
# property in devcontainer.json to cause VS Code its sub-processes (terminals, tasks,
# debugging) to execute as the user. Uncomment the next line if you want the entire
# container to run as this user instead. Note that, on Linux, you may need to
# ensure the UID and GID of the container user you create matches your local user.
# See https://aka.ms/vscode-remote/containers/non-root for details.
#
# user: vscode

# Uncomment if you want to override the service's Dockerfile to one in the .devcontainer
# folder. Note that the path of the Dockerfile and context is relative to the *primary*
# docker-compose.yml file (the first in the devcontainer.json "dockerComposeFile"
# array). The sample below assumes your primary file is in the root of your project.
#
image: hiveeyes/vscode:latest
build:
context: .
dockerfile: .devcontainer/vscode.dockerfile

volumes:
# Update this to wherever you want VS Code to mount the folder of your project
- .:/workspace:cached

# Uncomment the next line to use Docker from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker-compose for details.
- /var/run/docker.sock:/var/run/docker.sock

# Uncomment the next four lines if you will use a ptrace-based debugger like C++, Go, and Rust.
# cap_add:
# - SYS_PTRACE
# security_opt:
# - seccomp:unconfined

# Overrides default command so things don't shut down after the process ends.
command: /bin/sh -c "while sleep 1000; do :; done"
23 changes: 23 additions & 0 deletions .devcontainer/vscode.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Must build the normal dev image first!
FROM hiveeyes/dev:latest

ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# Create the non-root user
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
#
# [Optional] Add sudo support. Omit if you don't need to install software after connecting.
&& apt-get update \
&& apt-get install -y sudo \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME

# Make Python3.9 the default python (since some extension us /usr/bin/python3)
RUN ln -f -s /usr/local/bin/python3 /usr/bin/python3 && \
python3 -m pip install -U sphinx rstcheck snooty

# Add docker CLI tools
COPY --from=docker:dind /usr/local/bin/docker /usr/local/bin/
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* text=auto eol=lf
*.{cmd,[cC][mM][dD]} text eol=crlf
*.{bat,[bB][aA][tT]} text eol=crlf
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ presets.mk
.coverage
/spikes
/doc/build
_build/
17 changes: 17 additions & 0 deletions daemon.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# https://github.com/pycom/pycom-libraries/tree/master/pycom-docker-fw-build

FROM debian:buster-slim

RUN apt-get update && \
apt-get install -y python3 python3-pip && \
apt-get -y clean && \
python3 -m pip install -U pip setuptools

# ADD requirements-cpython.txt /tmp/build/requirements.txt
# RUN python3 -m pip install -r /tmp/build/requirements.txt

ADD dist/terkin*-py3-none-any.whl /tmp/build/
RUN python3 -m pip install /tmp/build/*.whl

WORKDIR /opt/terkin-datalogger
CMD [ "terkin", "--config=settings.py", "--daemon"]
11 changes: 9 additions & 2 deletions Dockerfile → dev.dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# https://github.com/pycom/pycom-libraries/tree/master/pycom-docker-fw-build

FROM debian:buster-slim
FROM python:3.9-slim-buster

RUN apt-get update && \
apt-get -y install wget git build-essential python python-serial python-virtualenv python3-virtualenv && \
apt-get -y install curl zip git wget && \
apt-get -y install build-essential python3 python3-pip && \
apt-get -y clean && \
mkdir /opt/frozen/ && cd /opt && \
wget -q https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-1.22.0-98-g4638c4f-5.2.0-20190827.tar.gz && \
tar -xzvf xtensa-esp32-elf-linux64-1.22.0-98-g4638c4f-5.2.0-20190827.tar.gz && \
Expand All @@ -12,3 +14,8 @@ RUN apt-get update && \
git clone --recursive https://github.com/pycom/pycom-micropython-sigfox.git

ADD tools/pycom-firmware-build /usr/bin/build
ADD requirements-cpython.txt requirements-docs.txt requirements-build.txt requirements-dev.txt requirements-test.txt /tmp/terkin/requirements/

RUN find /tmp/terkin/requirements/ -name "requirements*.txt" -type f -exec python3 -m pip install -r '{}' ';'

WORKDIR /src/terkin-datalogger
49 changes: 49 additions & 0 deletions doc/source/development/docker.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
##############################
Docker Development Environment
##############################


*************
Prerequisites
*************
You must have the Docker CLI tools and access to a Docker Host. to check this use:::

docker system info
git clone https://github.com/hiveeyes/terkin-datalogger.git
cd terkin-datalogger


**********************
Prepare working images
**********************
Use `docker compose` to build images:::

docker compose build

Use `docker compose` to build terkin packge wheels::

# This will generate python wheels in the `dist` folder.
docker compose up build


*************
Configuration
*************
Create configuration from blueprint:::

cp src/settings.raspberrypi-basic.py src/settings.py


***
Run
***
Run terkin-datalogger as a daemon within a docker compose service:::

docker compose up daemon
# Or in headless mode:
docker compose up -d daemon

***********************
VSCode Remote Container
***********************
You can use the `dev` container as a basis for a VSCode remote Development Environment.
51 changes: 36 additions & 15 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,47 @@ version: '3.7'

services:

portainer:
image: portainer/portainer
container_name: portainer
restart: unless-stopped
ports:
- 9000:9000
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./portainer:/data
# portainer:
# image: portainer/portainer
# container_name: portainer
# restart: unless-stopped
# ports:
# - 9000:9000
# volumes:
# - /var/run/docker.sock:/var/run/docker.sock
# - ./portainer:/data

hiveeyes:
dev:
build:
context: .
dockerfile: Dockerfile
image: debian/buster-slim
container_name: hiveeyes
restart: unless-stopped
dockerfile: dev.dockerfile
image: hiveeyes/dev:latest
volumes:
- ../terkin-datalogger:/opt/terkin-datalogger
- ./:/src/terkin-datalogger
stdin_open: true
tty: true
expose:
- "80"

build:
image: hiveeyes/dev:latest
volumes:
- ./:/src/terkin-datalogger
command: |
bash -c
"python3 setup.py clean --all &&
python3 setup_libraries.py bdist_wheel &&
python3 setup.py clean --all &&
python3 setup.py bdist_wheel &&
python3 setup.py clean --all"
daemon:
build:
context: .
dockerfile: daemon.dockerfile
volumes:
- ./src/settings.py:/opt/terkin-datalogger/settings.py:ro
image: hiveeyes/daemon:latest
ports:
- 8080:80

1 change: 0 additions & 1 deletion setup_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
test_suite='test',
install_requires=[],
extras_require={},
#tests_require=extras['test'],
dependency_links=[
],
entry_points={
Expand Down
3 changes: 3 additions & 0 deletions src/lib/terkin_cpython/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,6 @@ def start_ui(self):

finally:
ui.stop()

if __name__ == "__main__":
cli()

0 comments on commit cd247a1

Please sign in to comment.