Skip to content

Commit

Permalink
Refactor docker images in EVerest
Browse files Browse the repository at this point in the history
* Add devcontainer template
* Add easy-setup script `setup-devcontainer.sh`
* Move `mosquitto` image from `everest-utils` repository
* Move `steve` image from `everest-utils` repository
* Update README.md

Signed-off-by: Andreas Heinrich <[email protected]>
  • Loading branch information
andistorm committed Jul 17, 2024
1 parent 1e66ce8 commit 439d693
Show file tree
Hide file tree
Showing 13 changed files with 1,228 additions and 0 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/deploy-docker-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Build and push docker images

on:
pull_request: {}
push:
branches:
- '**'
tags:
- 'v*'

env:
REGISTRY: ghcr.io
DOCKER_DIRECTORY: docker/images
PLATFORMS: |
linux/amd64
PATH_TO_DEPLOY_DOCKER_IMAGES_WORKFLOW: .github/workflows/deploy-docker-images.yml

jobs:
env-setup:
# Since env variables can't be passed to reusable workflows, we need to pass them as outputs
name: Setup environment
runs-on: ubuntu-22.04
outputs:
docker_registry: ${{ env.REGISTRY }}
docker_directory: ${{ env.DOCKER_DIRECTORY }}
platforms: ${{ env.PLATFORMS }}
path_to_deploy_docker_images_workflow: ${{ env.PATH_TO_DEPLOY_DOCKER_IMAGES_WORKFLOW }}
steps:
- id: check
run: |
echo "Setting up environment"
mosquitto:
needs:
- env-setup
name: Build and push mosquitto docker image
uses: everest/everest-ci/.github/workflows/deploy-single-docker-image.yml@refactor-docker-images
secrets:
SA_GITHUB_PAT: ${{ secrets.SA_GITHUB_PAT }}
SA_GITHUB_USERNAME: ${{ secrets.SA_GITHUB_USERNAME }}
with:
image_name: ${{ github.event.repository.name }}/mosquitto
directory: ${{ needs.env-setup.outputs.docker_directory }}/mosquitto
docker_registry: ${{ needs.env-setup.outputs.docker_registry }}
github_ref_before: ${{ github.event.before }}
github_ref_after: ${{ github.event.after }}
platforms: ${{ needs.env-setup.outputs.platforms }}
depends_on_paths: |
${{ needs.env-setup.outputs.path_to_deploy_docker_images_workflow }}
steve:
needs:
- env-setup
name: Build and push steve docker image
uses: everest/everest-ci/.github/workflows/deploy-single-docker-image.yml@refactor-docker-images
secrets:
SA_GITHUB_PAT: ${{ secrets.SA_GITHUB_PAT }}
SA_GITHUB_USERNAME: ${{ secrets.SA_GITHUB_USERNAME }}
with:
image_name: ${{ github.event.repository.name }}/steve
directory: ${{ needs.env-setup.outputs.docker_directory }}/steve
docker_registry: ${{ needs.env-setup.outputs.docker_registry }}
github_ref_before: ${{ github.event.before }}
github_ref_after: ${{ github.event.after }}
platforms: ${{ needs.env-setup.outputs.platforms }}
depends_on_paths: |
${{ needs.env-setup.outputs.path_to_deploy_docker_images_workflow }}
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,46 @@ This subproject contains all utility files for setting up your development envir
You can install [edm](dependency_manager/README.md) very easy using pip.

All documentation and the issue tracking can be found in our main repository here: https://github.com/EVerest/everest

## Easy Dev Environment Setup

To setup a devcontainer in your workspace you can use the following command to run the `setup_devcontainer.sh` script locally.

Check notice on line 11 in README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

README.md#L11

Expected: 80; Actual: 126

### 1. Prerequisites

Create a new directory and navigate into it. This directory will be your new workspace or use an existing one.

Check notice on line 15 in README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

README.md#L15

Expected: 80; Actual: 110

```bash
mkdir my-workspace
cd my-workspace
```

### 2. Run the setup script

Run the following command to setup the devcontainer.

```bash
export BRANCH="main" && bash -c "$(curl -s --variable %BRANCH=main --expand-url https://raw.githubusercontent.com/EVerest/everest-dev-environment/{{BRANCH}}/devcontainer/setup-devcontainer.sh)"
```

The script will ask you for the following information:
1. Workspace directory: Default is the current directory. You can keep the default by pressing enter.

Check notice on line 31 in README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

README.md#L31

Expected: 80; Actual: 101
2. everest-dev-environment version: Default is 'main'. You can keep the default by pressing enter.

Check notice on line 32 in README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

README.md#L32

Expected: 80; Actual: 98

### 3. Open in VS Code

After the script has finished, open the workspace in Visual Studio Code.

```bash
code .
```

VS Code will ask you to reopen the workspace in a container. Click on the button `Reopen in Container`.

Check notice on line 42 in README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

README.md#L42

Expected: 80; Actual: 103

### 4. Getting started

As your set up dev environment suggests when you open a terminal, you can setup your EVerest workspace by running the following command:

Check notice on line 46 in README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

README.md#L46

Expected: 80; Actual: 136

```bash
edm init main
```
39 changes: 39 additions & 0 deletions devcontainer/setup-devcontainer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

set -e

read -p "Enter the workspace directory (default is the current directory): " WORKSPACE_DIR
if [ -z "$WORKSPACE_DIR" ]; then
WORKSPACE_DIR="./"
fi
WORKSPACE_DIR=$(realpath -m "$WORKSPACE_DIR")

read -p "Enter the version of the everest-dev-environment (default is 'main'): " VERSION
if [ -z "$VERSION" ]; then
VERSION="main"
fi

echo "Create the workspace directory '$WORKSPACE_DIR' if it does not exist"
mkdir -p $WORKSPACE_DIR

Check warning on line 17 in devcontainer/setup-devcontainer.sh

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

devcontainer/setup-devcontainer.sh#L17

Double quote to prevent globbing and word splitting.

if [ "$(ls -A $WORKSPACE_DIR)" ]; then

Check warning on line 19 in devcontainer/setup-devcontainer.sh

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

devcontainer/setup-devcontainer.sh#L19

Double quote to prevent globbing and word splitting.
# The workspace directory is not empty, warning do you want to continue?
read -p "The workspace directory is not empty, do you want to continue? (y/N): " -r
if [[ $REPLY =~ ^[Nn]$ || $REPLY = "" ]]; then
echo "Exiting.."
exit 1
elif [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Invalid input. Exiting.."
exit 1
fi
fi

TMP_DIR="$WORKSPACE_DIR/tmp-everest-dev-environment"
echo "Clone the everest-dev-environment repository to the workspace directory with the version $VERSION, temporarily.."
git clone --quiet --depth 1 --single-branch --branch "$VERSION" https://github.com/EVerest/everest-dev-environment.git "$TMP_DIR"

echo "Copy the template devcontainer configuration files to the workspace directory"
cp -n -r $TMP_DIR/devcontainer/template/* $WORKSPACE_DIR/

Check warning on line 36 in devcontainer/setup-devcontainer.sh

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

devcontainer/setup-devcontainer.sh#L36

Double quote to prevent globbing and word splitting.

echo "Remove the everest-dev-environment repository"
rm -rf "$TMP_DIR"
49 changes: 49 additions & 0 deletions devcontainer/template/.devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
version: "3.6"

volumes:
ocpp-db-data:
external: false
node-red-data:
external: false

services:
mqtt-server:
# LTODO: update tag
image: ghcr.io/everest/everest-dev-environment/mosquitto:refactor-docker-images
ports:
# allow multiple ports for host to avoid conflicts with other dev environments
- 1883-1983:1883
- 9001-9101:9001

ocpp-db:
image: mariadb:10.4.30 # pinned to patch-version because https://github.com/steve-community/steve/pull/1213
volumes:
- ocpp-db-data:/var/lib/mysql
ports:
# allow multiple ports for host to avoid conflicts with other dev environments
- 13306-13406:3306
environment:
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
MYSQL_DATABASE: ocpp-db
MYSQL_USER: ocpp
MYSQL_PASSWORD: ocpp

steve:
# LTODO: update tag
image: ghcr.io/everest/everest-dev-environment/steve:refactor-docker-images
ports:
# allow multiple ports for host to avoid conflicts with other dev environments
- 8180-8280:8180
- 8443-8543:8443
depends_on:
- ocpp-db

nodered:
image: nodered/node-red
volumes:
- node-red-data:/data
depends_on:
- mqtt-server
ports:
# allow multiple ports for host to avoid conflicts with other dev environments
- 1880-1980:1880
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# syntax=docker/dockerfile:1
# LTODO: Update tag
FROM ghcr.io/everest/everest-ci/dev-env-base:refactor-docker-images

RUN sudo apt update

Check failure on line 5 in devcontainer/template/.devcontainer/general-devcontainer/Dockerfile

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

devcontainer/template/.devcontainer/general-devcontainer/Dockerfile#L5

Do not use sudo as it leads to unpredictable behavior. Use a tool like gosu to enforce root

RUN echo "echo \"🏔️ 🚘 Welcome to the EVerest development environment!\"" >> ${HOME}/.bashrc

Check notice on line 7 in devcontainer/template/.devcontainer/general-devcontainer/Dockerfile

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

devcontainer/template/.devcontainer/general-devcontainer/Dockerfile#L7

Double quote to prevent globbing and word splitting.
RUN echo "echo \"To initialize the EVerest workspace please run the following command:\"" >> ${HOME}/.bashrc

Check notice on line 8 in devcontainer/template/.devcontainer/general-devcontainer/Dockerfile

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

devcontainer/template/.devcontainer/general-devcontainer/Dockerfile#L8

Double quote to prevent globbing and word splitting.
RUN echo "echo \"edm init main\"" >> ${HOME}/.bashrc

Check notice on line 9 in devcontainer/template/.devcontainer/general-devcontainer/Dockerfile

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

devcontainer/template/.devcontainer/general-devcontainer/Dockerfile#L9

Double quote to prevent globbing and word splitting.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "EVerest Debian Devenvironment2",
"dockerComposeFile": ["../docker-compose.yml", "./docker-compose.devcontainer.yml"],
"service": "devcontainer",
"remoteUser": "docker",
"workspaceFolder": "/workspace",
"customizations": {
"vscode": {
"settings": {
"terminal.integrated.profiles.linux": {
"bash": {
"path": "/bin/bash",
"icon": "terminal-bash",
"args": ["-l"]
}
},
"terminal.integrated.defaultProfile.linux": "bash",
"python.pythonPath": "/usr/bin/python3",
"python.defaultInterpreterPath": "/usr/bin/python3",
"editor.rulers": [79, 120],
// RST/Sphinx language server
"esbonio.sphinx.buildDir": "${workspaceFolder}/everest/docs/_build",
"esbonio.sphinx.confDir": "${workspaceFolder}/everest/docs",
// RST
"restructuredtext.preview.scrollEditorWithPreview": false,
"restructuredtext.pythonRecommendation.disabled": true,
"liveServer.settings.root": "/everest/docs/_build/html"
},
"extensions": [
// language support CPP
"ms-vscode.cpptools",
// language support cmake
"twxs.cmake",
"ms-vscode.cmake-tools",
// language support python
"ms-python.python",
// language support restructured text
"lextudio.restructuredtext",
"trond-snekvik.simple-rst",
// doc live server
"ritwickdey.liveserver"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: "3.6"

services:
devcontainer:
build:
context: ./general-devcontainer
dockerfile: Dockerfile
volumes:
- type: bind
source: ..
target: /workspace
command: sleep infinity
environment:
MQTT_SERVER_ADRESS: mqtt-server
MQTT_SERVER_PORT: 1883
3 changes: 3 additions & 0 deletions docker/images/mosquitto/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM eclipse-mosquitto:2.0.10

COPY mosquitto.conf /mosquitto/config/mosquitto.conf
Loading

0 comments on commit 439d693

Please sign in to comment.