Skip to content

Commit

Permalink
file structure & re-factored dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
sinamics committed Jan 26, 2022
1 parent 70964c9 commit a5ad238
Show file tree
Hide file tree
Showing 30 changed files with 131 additions and 169 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@
"mikestead.dotenv"
],
// Uncomment the next line to run commands after the container is created - for example installing curl.
"postCreateCommand": "sudo docker/bin/./install.sh && sudo docker/bin/./install-dev-addon.sh"
"postCreateCommand": "sudo docker/bin/./install-dev-addon.sh"
}
8 changes: 4 additions & 4 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
{
"name": "Linux",
"includePath": [
"/usr/include/gstreamer-1.0",
"/usr/include/glib-2.0/",
"/usr/lib/arm-linux-gnueabihf/glib-2.0/include/",
// "/usr/include/gstreamer-1.0",
// "/usr/include/glib-2.0/",
// "/usr/lib/arm-linux-gnueabihf/glib-2.0/include/",
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
// "compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-arm"
Expand Down
2 changes: 1 addition & 1 deletion backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const server = async () => {
app.use(cors());

if (process.env.NODE_ENV === 'production') {
console.log('Running Production Server'); // eslint-disable-line no-console
console.log('Running Production Server port:' + process.env.SERVER_PORT); // eslint-disable-line no-console
app.use(compression());
app.use(express.static(path.join(__dirname, '../../frontend/build')));

Expand Down
4 changes: 1 addition & 3 deletions bin/includes/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "db.h"
#include "utils.h"
#include "app.h"
#include <cstdlib>

int App::serverport()
{
Expand All @@ -27,8 +28,5 @@ int App::serverport()
utils.exec_p(sed.c_str());
std::cout << ">> WebPort changed " << app.webPort << '\n';

//restart docker container
// std::string systemd = "docker restart uavcast";
// utils.exec_p(systemd.c_str());
return 0;
}
Empty file modified bin/mavlink/mavlink-routerd-amd64
100755 → 100644
Empty file.
Empty file modified bin/mavlink/mavlink-routerd-arm
100755 → 100644
Empty file.
Empty file modified bin/mavlink/mavlink-routerd-arm64
100755 → 100644
Empty file.
4 changes: 2 additions & 2 deletions compile_release.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ if (( $docker_local > 0 )); then
docker buildx create --name uavcast_builder
docker buildx use uavcast_builder
docker buildx build --pull --rm -f "docker/Dockerfile.publish" \
--platform linux/arm \
--platform linux/arm/v7 \
-t sinamics/uavcast:$version_arg "." --output "type=docker,name=sinamics/uavcast:${version_arg}"

# docker build --pull --rm -f "Dockerfile" -t sinamics/uavcast:$version_arg "."
Expand All @@ -123,7 +123,7 @@ if (( $docker_publish > 0 )); then
docker run --privileged --rm tonistiigi/binfmt --install all

docker buildx build --pull --rm -f "docker/Dockerfile.publish" \
--platform linux/arm,linux/arm64,linux/amd64 \
--platform linux/arm/v7,linux/arm64,linux/amd64 \
-t $image_name:$version_arg "." --push

# docker login #-u $DOCKER_USER -p $DOCKER_PASS
Expand Down
18 changes: 17 additions & 1 deletion docker/Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ RUN groupadd --gid $USER_GID $USERNAME \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME

RUN sudo usermod -a -G docker uavcast

RUN apt-get update && apt-get install -y \
libcppunit-dev \
libjsoncpp-dev \
Expand All @@ -26,16 +28,30 @@ RUN apt-get update && apt-get install -y \
libcurl4-nss-dev \
sqlite3 \
libsqlite3-dev

# systemctl3
COPY init/systemctl3.py /bin/systemctl
COPY init/systemctl3.py /bin/systemctl3.py
COPY init/journalctl3.py /bin/journalctl

# Copy systemd files
COPY ["init/mavlink-router.service", \
"init/uavcast-camera.service", \
"init/uavcast-vpn.service", \
"init/uavcast-web.service", \
"init/uavcast.service", "/etc/systemd/system/"]

RUN mkdir -p /app/uavcast/data && chown -R uavcast /app/uavcast/data

RUN sudo touch /var/run/docker.sock
RUN sudo chmod 666 /var/run/docker.sock
RUN sudo chown uavcast:docker /var/run/docker.sock

RUN chmod +x /bin/systemctl \
/bin/systemctl3.py \
/bin/journalctl

# zerotier installation
RUN sudo curl -s https://install.zerotier.com/ | sudo bash

ENV NODE_ENV=development
34 changes: 22 additions & 12 deletions docker/Dockerfile.publish
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,15 @@ ARG USER_GID=$USER_UID
# Create the 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.
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME


COPY --from=gcc /gcc/build ./bin/build
COPY --from=frontend /frontend/build ./frontend/build

COPY --from=backend /backend/dist ./backend/dist
COPY --from=backend /backend/node_modules ./backend/node_modules
COPY --from=backend /backend/ormconfig.js ./backend
# COPY --from=backend /backend/node_sqlite3.node ./backend

RUN apt-get update && apt-get install -y \
libcppunit-dev \
Expand All @@ -120,16 +116,17 @@ RUN apt-get update && apt-get install -y \
sqlite3 \
libsqlite3-dev

# TODO re-run installation of sqlite3, it fails for some reason if not.
RUN cd backend && npm i sqlite3

# systemctl3
COPY init/systemctl3.py /bin/systemctl
COPY init/systemctl3.py /bin/systemctl3.py
COPY init/journalctl3.py /bin/journalctl

# Create mavlink directory
RUN mkdir -p /etc/mavlink-router

## copy in files and folder
COPY ["bin/mavlink/mavlink-routerd-${TARGETARCH}", "./bin/mavlink/mavlink-routerd"]
COPY ["etc/mavlink-router-example.conf", "/etc/mavlink-router/main.conf"]
COPY ["bin/python", "./bin/python"]
COPY ["etc", "./etc"]
COPY ["docker", "./docker"]
Expand All @@ -142,18 +139,31 @@ RUN chmod +x -R ./docker/bin \

RUN sudo touch /var/run/docker.sock
RUN sudo chmod 666 /var/run/docker.sock

# #changes the ownership of /var/run/docker.sock
RUN sudo chown uavcast:docker /var/run/docker.sock

# zerotier installation
RUN sudo curl -s https://install.zerotier.com/ | sudo bash

# Copy systemd files
COPY ["init/mavlink-router.service", \
"init/uavcast-camera.service", \
"init/uavcast-vpn.service", \
"init/uavcast-web.service", \
"init/uavcast.service", "/etc/systemd/system/"]

#gives uavcast user permissions to access /var/run/docker.sock
RUN sudo usermod -a -G docker root

# enable web interface and mavlink as default
RUN systemctl enable uavcast-web
RUN systemctl enable mavlink-router

# set container env production
ENV NODE_ENV=production

RUN ["/app/uavcast/docker/bin/./install.sh"]
RUN ["/app/uavcast/docker/bin/./install-prod-addon.sh"]
RUN ["docker/bin/./install-prod-addon.sh"]

ENTRYPOINT ["/app/uavcast/docker/bin/entrypoint.sh"]
ENTRYPOINT ["docker/bin/entrypoint.sh"]
CMD ["/bin/systemctl"]
# ENTRYPOINT ["tail", "-f", "/dev/null"]

5 changes: 3 additions & 2 deletions docker/bin/entrypoint.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env bash
set -e
# set -e

# Make sure we set the webport stored in the database, if user uses another port than standard 80
/app/uavcast/bin/build/uav_main -p >> waitforit.txt

exec "$@"

exec "$@"
Empty file modified docker/bin/install-dev-addon.sh
100755 → 100644
Empty file.
5 changes: 1 addition & 4 deletions docker/bin/install-prod-addon.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#!/bin/bash
#!/usr/bin/env bash
# ----------------------------------------------------------------
# UAVcast installation file.
# Author Bernt Christian Egeland
#
# !Production specific addons
# ----------------------------------------------------------------

# Set folders
APPROOT="/app/uavcast"



138 changes: 0 additions & 138 deletions docker/bin/install.sh

This file was deleted.

2 changes: 1 addition & 1 deletion frontend/.env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
REACT_APP_UAVCAST_VER="5.0.0-dev-1"
REACT_APP_UAVCAST_VER="5.0.0-dev2"
Empty file modified frontend/src/translations/locales/Readme.md
100755 → 100644
Empty file.
Empty file modified frontend/src/translations/locales/cn.json
100755 → 100644
Empty file.
Empty file modified frontend/src/translations/locales/en.json
100755 → 100644
Empty file.
Empty file modified frontend/src/translations/locales/es.json
100755 → 100644
Empty file.
Empty file modified frontend/src/translations/locales/it.json
100755 → 100644
Empty file.
Empty file modified frontend/src/translations/locales/nl.json
100755 → 100644
Empty file.
Empty file modified frontend/src/translations/locales/pl.json
100755 → 100644
Empty file.
Empty file modified frontend/src/translations/locales/pt.json
100755 → 100644
Empty file.
Empty file modified frontend/src/translations/locales/ru.json
100755 → 100644
Empty file.
Empty file modified frontend/src/translations/locales/tr.json
100755 → 100644
Empty file.
11 changes: 11 additions & 0 deletions init/mavlink-router.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=MAVLink Router
[Service]
Type=simple
ExecStart=/app/uavcast/bin/mavlink/mavlink-routerd
StandardOutput=journal+console
StandardError=inherit
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
16 changes: 16 additions & 0 deletions init/uavcast-camera.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
Description=uavcast-camera controller
Requires=network-online.target
Wants=network-online.target
After=network-online.target
[Service]
WorkingDirectory=/app/uavcast/bin/build
Type=simple
GuessMainPID=no
ExecStart=/app/uavcast/bin/build/uav_camera -start
KillMode=control-group
SyslogIdentifier=uavcast-camera
StandardOutput=journal+console
StandardError=inherit
[Install]
WantedBy=multi-user.target
Loading

0 comments on commit a5ad238

Please sign in to comment.