Skip to content

Commit

Permalink
Merge pull request #286 from threefoldtech/development_mariadb-demo
Browse files Browse the repository at this point in the history
add mariadb demo images
  • Loading branch information
Omarabdul3ziz authored Aug 13, 2024
2 parents f764991 + 0ce7f78 commit e08373b
Show file tree
Hide file tree
Showing 30 changed files with 24,084 additions and 3 deletions.
4 changes: 4 additions & 0 deletions tfgrid3/mariadb/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
MYSQL_ROOT_PASSWORD=rootpassword
MYSQL_DATABASE=mydb
MYSQL_USER=mysql
MYSQL_PASSWORD=password
18 changes: 18 additions & 0 deletions tfgrid3/mariadb/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM mariadb

ENV DEBIAN_FRONTEND=noninteractive
RUN apt update && apt -y install wget openssh-server

RUN wget https://github.com/prometheus/node_exporter/releases/download/v1.8.2/node_exporter-1.8.2.linux-amd64.tar.gz && \
tar xvfz node_exporter-1.8.2.linux-amd64.tar.gz && \
mv node_exporter-1.8.2.linux-amd64/node_exporter /usr/local/bin

RUN wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.15.1/mysqld_exporter-0.15.1.linux-amd64.tar.gz && \
tar xvfz mysqld_exporter-0.15.1.linux-amd64.tar.gz && \
mv mysqld_exporter-0.15.1.linux-amd64/mysqld_exporter /usr/local/bin

RUN wget -O /sbin/zinit https://github.com/threefoldtech/zinit/releases/download/v0.2.5/zinit && chmod +x /sbin/zinit
COPY rootfs /

EXPOSE 9500 9501
ENTRYPOINT [ "/sbin/zinit", "init" ]
17 changes: 17 additions & 0 deletions tfgrid3/mariadb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# MariaDB

the image contains:

- mariadb server
- node exporter
- mysqld exporter

## ports

- `9500` for mysqld exporter
- `9501` for node exporter

## image

- docker: omarabdul3ziz/mariadb
- [flist](https://hub.grid.tf/omarabdulaziz.3bot/omarabdul3ziz-mariadb-latest.flist)
6 changes: 6 additions & 0 deletions tfgrid3/mariadb/rootfs/etc/zinit/mariadb-setup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
exec: |
bash -c '
mariadb-install-db --user=mysql
'
oneshot: true
7 changes: 7 additions & 0 deletions tfgrid3/mariadb/rootfs/etc/zinit/mariadb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
exec: |
bash -c '
mariadbd --user=mysql
'
after:
- mariadb-setup
7 changes: 7 additions & 0 deletions tfgrid3/mariadb/rootfs/etc/zinit/mysqld-exporter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
exec: |
bash -c '
mysqld_exporter \
--web.listen-address=:9500 \
--mysqld.username=${MYSQL_USER}:${MYSQL_PASSWORD} \
--mysqld.address=localhost:3306
'
1 change: 1 addition & 0 deletions tfgrid3/mariadb/rootfs/etc/zinit/node-exporter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exec: node_exporter --web.listen-address=:9501
1 change: 1 addition & 0 deletions tfgrid3/mariadb/rootfs/etc/zinit/sshd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exec: /usr/sbin/sshd -D
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM ubuntu

ENV DEBIAN_FRONTEND=noninteractive
RUN apt update && apt install -y wget openssh-server

RUN apt update && \
apt-get install -y \
RUN apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
Expand All @@ -17,7 +17,6 @@ RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - &&\

RUN apt-get update && apt-get install -y docker-ce

RUN apt install -y wget openssh-server

COPY . .

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions tfgrid3/mariadb_aio/etc/zinit/sshkey.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
exec: |
bash -c '
if [ ! -z "$SSH_KEY" ]; then
mkdir -p /var/run/sshd
mkdir -p /root/.ssh
touch /root/.ssh/authorized_keys
chmod 700 /root/.ssh
chmod 600 /root/.ssh/authorized_keys
echo "$SSH_KEY" >> /root/.ssh/authorized_keys
fi
'
oneshot: true
24 changes: 24 additions & 0 deletions tfgrid3/monitor/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM ubuntu

ENV DEBIAN_FRONTEND=noninteractive

RUN apt update && apt -y install wget openssh-server

RUN wget https://github.com/prometheus/prometheus/releases/download/v2.33.5/prometheus-2.33.5.linux-amd64.tar.gz && \
tar xvf /prometheus-2.33.5.linux-amd64.tar.gz && \
useradd --no-create-home --shell /bin/false prometheus && \
mv /prometheus-2.33.5.linux-amd64/prometheus /usr/local/bin/ && \
chown prometheus:prometheus /usr/local/bin/prometheus && \
mkdir /var/lib/prometheus && \
chown prometheus:prometheus /var/lib/prometheus

RUN apt -y install adduser libfontconfig1 musl && \
wget https://dl.grafana.com/enterprise/release/grafana-enterprise_11.1.3_amd64.deb && \
dpkg -i grafana-enterprise_11.1.3_amd64.deb

RUN wget -O /sbin/zinit https://github.com/threefoldtech/zinit/releases/download/v0.2.5/zinit && \
chmod +x /sbin/zinit

COPY rootfs .

ENTRYPOINT [ "/sbin/zinit", "init" ]
18 changes: 18 additions & 0 deletions tfgrid3/monitor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Monitor

this image include prometheus and grafana that visualize a monitor with a full node dashboard.

## Envvars

- `PROM_TARGETS`: comma-separated string of hosts for prometheus to scrap
- `SSH_KEY`

## Ports

- `3000` for grafana dashboard
- `9090` for prometheus web ui

## image

- docker: omarabdul3ziz/monitor
- [flist](https://hub.grid.tf/omarabdulaziz.3bot/omarabdul3ziz-monitor-latest.flist)
26 changes: 26 additions & 0 deletions tfgrid3/monitor/rootfs/etc/scripts/config-prom.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# Check if the PROM_TARGETS environment variable is set
if [ -z "$PROM_TARGETS" ]; then
echo "PROM_TARGETS environment variable is not set."
exit 1
fi

# Split the PROM_TARGETS string into an array
IFS=',' read -ra TARGETS <<< "$PROM_TARGETS"

mkdir -p /etc/prometheus
touch /etc/prometheus/prometheus.yml

# Generate the Prometheus config with dynamic targets
cat <<EOF > /etc/prometheus/prometheus.yml
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'mariadb-exporter'
static_configs:
- targets: [$(printf "'%s'," "${TARGETS[@]}" | sed 's/,$//')]
EOF

echo "Prometheus configuration generated successfully."
3 changes: 3 additions & 0 deletions tfgrid3/monitor/rootfs/etc/zinit/graf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exec: grafana-server --homepath /usr/share/grafana
after:
- prom
2 changes: 2 additions & 0 deletions tfgrid3/monitor/rootfs/etc/zinit/prom-setup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
exec: bash /etc/scripts/config-prom.sh
oneshot: true
3 changes: 3 additions & 0 deletions tfgrid3/monitor/rootfs/etc/zinit/prom.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exec: prometheus --config.file=/etc/prometheus/prometheus.yml
after:
- prom-setup
1 change: 1 addition & 0 deletions tfgrid3/monitor/rootfs/etc/zinit/sshd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exec: /usr/sbin/sshd -D
14 changes: 14 additions & 0 deletions tfgrid3/monitor/rootfs/etc/zinit/sshkey.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
exec: |
bash -c '
if [ ! -z "$SSH_KEY" ]; then
mkdir -p /var/run/sshd
mkdir -p /root/.ssh
touch /root/.ssh/authorized_keys
chmod 700 /root/.ssh
chmod 600 /root/.ssh/authorized_keys
echo "$SSH_KEY" >> /root/.ssh/authorized_keys
fi
'
oneshot: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: 1

providers:
- name: Default
folder: Services
type: file
options:
path: /var/lib/grafana/dashboards
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: 1

datasources:
- name: Prometheus
type: prometheus
url: http://localhost:9090
isDefault: true
access: proxy
editable: true
Loading

0 comments on commit e08373b

Please sign in to comment.