Skip to content

Commit

Permalink
Merge pull request #498 from MyElectricalData/feat/devcontainer
Browse files Browse the repository at this point in the history
Feat/devcontainer
  • Loading branch information
m4dm4rtig4n authored Feb 19, 2024
2 parents ed0ba55 + 211371e commit f4b241e
Show file tree
Hide file tree
Showing 18 changed files with 634 additions and 620 deletions.
22 changes: 4 additions & 18 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,15 @@ RUN apt-get update \
&& curl -fsSL https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/gpg | apt-key add - 2>/dev/null \
&& echo "deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]') $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list \
&& apt-get update \
&& apt-get install -y docker-ce-cli
&& apt-get install -y docker-ce-cli zsh git software-properties-common grc wget curl

# make the LOCAL variable and install it
ARG LOCAL=fr_FR.UTF-8
RUN apt-get install -y locales && rm -rf /var/lib/apt/lists/* \
&& localedef -i $(echo ${LOCAL} | cut -d "." -f1) -c -f $(echo ${LOCAL} | cut -d "." -f2) -A /usr/share/locale/locale.alias ${LOCAL}
ENV LANG ${LOCAL}

RUN docker context use default
RUN docker buildx use default

# Install Docker Compose
RUN export LATEST_COMPOSE_VERSION=$(curl -sSL "https://api.github.com/repos/docker/compose/releases/latest" | grep -o -P '(?<="tag_name": ").+(?=")') \
&& curl -sSL "https://github.com/docker/compose/releases/download/${LATEST_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose \
&& chmod +x /usr/local/bin/docker-compose

# [Optional] If your pip requirements rarely change, uncomment this section to add them to the image.
COPY app/requirement.txt /tmp/pip-tmp/
RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirement.txt \
&& rm -rf /tmp/pip-tmp

# [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>

WORKDIR /workspace
RUN ln -s /workspace/app /app
RUN ln -s /workspace/data /data
WORKDIR /workspace
130 changes: 65 additions & 65 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
// 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.224.2/containers/docker-existing-docker-compose
// If you want to run as a non-root user in the container, see .devcontainer/docker-compose.yml.
{
"name": "enedisgateway2mqtt development",
// 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.
"name": "MyElectricalData development",
"dockerComposeFile": [
"docker-compose.dev.yml",
"docker-compose.yaml"
],
"shutdownAction": "stopCompose",

// Set *default* container specific settings.json values on container create.
"settings": {
"python.defaultInterpreterPath": "/usr/local/bin/python",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint",
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "/usr/bin/zsh"
}
},
"terminal.integrated.defaultProfile.linux": "zsh",
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"files.trimTrailingWhitespace": true
},

// 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.
"postCreateCommand": "/bin/bash -lc ./.devcontainer/post-install.sh",
// "postCreateCommand": "make init-devcontainer",
"postStartCommand": "make dev",
"service": "workspace",

// 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",

"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"ms-azuretools.vscode-docker",
"timonwong.shellcheck",
"esbenp.prettier-vscode"
],

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

// 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": "apt-get update && apt-get install -y curl",

// Uncomment to connect as a non-root user if you've added one. See https://aka.ms/vscode-remote/containers/non-root.
// "remoteUser": "vscode"
"forwardPorts": [],
"customizations": {
"vscode": {
"extensions": [
"mikoz.black-py",
"ms-python.black-formatter",
"genuitecllc.codetogether",
"Codium.codium",
"tamasfe.even-better-toml",
"ms-azuretools.vscode-docker",
"ms-python.flake8",
"mhutchie.git-graph",
"donjayamanne.githistory",
"huizhou.githd",
"github.vscode-github-actions",
"ecmel.vscode-html-css",
"ms-python.isort",
"elagil.pre-commit-helper",
"MarkLarah.pre-commit-vscode",
"ms-python.vscode-pylance",
"ms-python.pylint",
"zeshuaro.vscode-python-poetry",
"the-compiler.python-tox",
"ms-python.python",
"ms-python.debugpy",
"aaron-bond.better-comments",
"ms-vscode-remote.remote-containers",
"ms-vscode.makefile-tools"
]
},
"settings": {
"terminal.integrated.defaultProfile.linux": "zsh",
"python.testing.pytestEnabled": true,
"black-formatter.args": [
"--line-height 119"
],
"editor.wordWrapColumn": 119,
"black-py.useIntegratedTerminal": true,
"git.enableSmartCommit": true,
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"editor.defaultFormatter": "ms-python.black-formatter",
"pylint.cwd": "${workspaceFolder}/src",
"pylint.importStrategy": "fromEnvironment",
"flake8.cwd": "${workspaceFolder}/src",
"flake8.importStrategy": "fromEnvironment",
"editor.wordWrap": "wordWrapColumn",
"python.analysis.autoImportCompletions": false,
"python.analysis.typeCheckingMode": "off",
"python.analysis.extraPaths": [
"./src"
],
"editor.rulers": [ 119 ],
"better-comments.highlightPlainText": true,
"black-formatter.importStrategy": "fromEnvironment",
"editor.defaultFoldingRangeProvider": "ms-python.black-formatter",
"editor.renderWhitespace": "all"
}
}
}
62 changes: 0 additions & 62 deletions .devcontainer/docker-compose.dev.yml

This file was deleted.

61 changes: 27 additions & 34 deletions dev/docker-compose.yaml → .devcontainer/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
version: "3.9"
# version: "3.9"
services:
# myelectricaldata_import:
# build: ./../
## image: m4dm4rtig4n/myelectricaldata:0.8.13-beta2
# environment:
# TZ: Europe/Paris
# ports:
# - '5000:5000'
# links:
# - influxdb
# - mosquitto
# - postgres
# volumes:
# - ./../data/cache:/data
# - ./../data/log:/log
# - ./../app:/app
workspace:
build:
context: ..
# ssh:
# - default
dockerfile: .devcontainer/Dockerfile
args:
# 3, 3.10, 3.9, 3.8, 3.7, 3.6, 3-bullseye, 3.10-bullseye, 3.9-bullseye, 3.8-bullseye,
# 3.7-bullseye, 3.6-bullseye, 3-buster, 3.10-buster, 3.9-buster, 3.8-buster, 3.7-buster, 3.6-buster
VARIANT: 3-bullseye
LOCAL: fr_FR.UTF-8
ports:
- 8080:8080
volumes:
- /usr/local/share/ca-certificates/:/usr/local/share/ca-certificates/
- ${HOME}/.ssh:/home/vscode/.ssh
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
- ..:/workspace:cached
- /var/run/docker.sock:/var/run/docker.sock
command: sleep infinity

influxdb:
image: influxdb:2.4
ports:
- '8086:8086'
- '8086'
volumes:
- ./../data/influxdb:/var/lib/influxdb2
healthcheck:
Expand All @@ -46,8 +52,8 @@ services:
- ./../data/mosquitto:/data
- ./../mosquitto:/mosquitto/config/
ports:
- 1883:1883
- 9001:9001
- 1883
- 9001

mqtt_explorer:
image: smeagolworms4/mqtt-explorer
Expand All @@ -60,7 +66,7 @@ services:
ports:
- 4000:4000

# ----------------------------------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------------------------------
# DATABASE
postgres:
image: postgres
Expand All @@ -71,23 +77,10 @@ services:
POSTGRES_DB: myelectricaldata
PGDATA: /var/lib/postgresql/data/pgdata
ports:
- "5432:5432"
- 5432
volumes:
- ./../data/postgresql/data:/var/lib/postgresql/data
- ./../init.sql:/docker-entrypoint-initdb.d/init.sql

mysql:
image: mariadb
restart: always
environment:
MARIADB_USER: myelectricaldata
MARIADB_PASSWORD: myelectricaldata
MARIADB_ROOT_PASSWORD: myelectricaldata
MARIADB_DATABASE : myelectricaldata
ports:
- "3306:3306"
volumes:
- ./../data/mysql/data:/var/lib/mysql

volumes:
mydata:
26 changes: 0 additions & 26 deletions .devcontainer/docker-compose.yml

This file was deleted.

25 changes: 25 additions & 0 deletions .devcontainer/post-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
echo "Configure ZSH"
# Configure ZSH
mkdir -p ~/.local/share/fonts
curl -fL https://raw.githubusercontent.com/ryanoasis/nerd-fonts/master/patched-fonts/DroidSansMono/DroidSansMNerdFontMono-Regular.otf --output ~/.local/share/fonts/DroidSansMNerdFontMono-Regular.otf
git clone https://github.com/tarjoilija/zgen.git "${HOME}/.zgen"
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
cp .devcontainer/zshrc "${HOME}/.zshrc"
echo ""
echo "Install ASDF"
git clone https://github.com/asdf-vm/asdf.git ~/.asdf
echo '. "$HOME/.asdf/asdf.sh"' >> ~/.bashrc
echo '. "$HOME/.asdf/completions/asdf.bash"' >> ~/.bashrc
echo ""
echo "Source bashrc"
export PATH=~/.asdf/bin:~/.asdf/shims:$PATH
POETRY_VERSION=$(cat .tool-versions|grep 'poetry' | cut -d " " -f 2)
export PATH=~/.asdf/installs/poetry/$POETRY_VERSION/bin:$PATH
echo ""
echo "Disable SSL check in Curl"
echo "insecure" >> ${HOME}/.curlrc
sudo update-ca-certificates --fresh
echo ""
echo "Install environment"
make install
Loading

0 comments on commit f4b241e

Please sign in to comment.