Cronjob added inside container
This commit is contained in:
17
Dockerfile
17
Dockerfile
@@ -1,4 +1,4 @@
|
|||||||
FROM ruby:2.7
|
FROM ruby:3.1
|
||||||
|
|
||||||
ENV BUILD_PACKAGES="apt-utils build-essential curl less nodejs sudo wget zsh libmariadb-dev libserialport-dev cron"
|
ENV BUILD_PACKAGES="apt-utils build-essential curl less nodejs sudo wget zsh libmariadb-dev libserialport-dev cron"
|
||||||
|
|
||||||
@@ -14,7 +14,18 @@ COPY Gemfile Gemfile.lock ./
|
|||||||
RUN \
|
RUN \
|
||||||
apt-get update -qq && \
|
apt-get update -qq && \
|
||||||
apt-get install -y $BUILD_PACKAGES && \
|
apt-get install -y $BUILD_PACKAGES && \
|
||||||
bundle install
|
# Fix bundler version BEFORE bundle install
|
||||||
|
gem install bundler -v "$(grep -A 1 'BUNDLED WITH' Gemfile.lock | tail -n 1)" && \
|
||||||
|
bundle install && \
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# Copy cron file (if you use /etc/cron.d style)
|
||||||
|
COPY reportcron /etc/cron.d/reportcron
|
||||||
|
RUN chmod 0644 /etc/cron.d/reportcron && touch /var/log/cron.log
|
||||||
|
|
||||||
|
# Add entrypoint script
|
||||||
|
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
|
||||||
|
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
||||||
|
|
||||||
|
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
|
||||||
|
|
||||||
CMD ["/bin/bash -c ruby ./smartmeter.rb"]
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ services:
|
|||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
image: mysql:8.3
|
image: mysql:8.3
|
||||||
volumes:
|
volumes:
|
||||||
- $PWD/data:/var/lib/mysql
|
- mysql-data:/var/lib/mysql
|
||||||
ports:
|
ports:
|
||||||
- 3306:3306
|
- 3306:3306
|
||||||
environment:
|
environment:
|
||||||
@@ -12,15 +12,19 @@ services:
|
|||||||
MYSQL_DATABASE: smartmeter
|
MYSQL_DATABASE: smartmeter
|
||||||
smartmeter:
|
smartmeter:
|
||||||
container_name: smartmeter
|
container_name: smartmeter
|
||||||
|
labels:
|
||||||
|
- diun.enable=false
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
build: .
|
build: .
|
||||||
|
environment:
|
||||||
|
MQTT_HOST: 10.0.0.240
|
||||||
command: 'ruby ./smartmeter.rb'
|
command: 'ruby ./smartmeter.rb'
|
||||||
#devices:
|
devices:
|
||||||
# - "/dev/ttyUSB1:/dev/ttyUSB0"
|
- "/dev/ttyUSB0:/dev/ttyUSB0"
|
||||||
volumes:
|
volumes:
|
||||||
- .:/usr/src/app
|
- .:/usr/src/app
|
||||||
depends_on:
|
depends_on:
|
||||||
- db
|
- db
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
mysql-data:
|
||||||
|
|||||||
10
docker-entrypoint.sh
Normal file
10
docker-entrypoint.sh
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
|
unset BUNDLE_PATH
|
||||||
|
unset BUNDLE_BIN
|
||||||
|
|
||||||
|
# Start cron in background
|
||||||
|
cron
|
||||||
|
|
||||||
|
# Start your Ruby process in foreground
|
||||||
|
ruby /usr/src/app/smartmeter.rb
|
||||||
3
reportcron
Normal file
3
reportcron
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
PATH=/usr/local/bundle/bin:/usr/local/bundle/gems/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||||
|
GEM_HOME=/usr/local/bundle
|
||||||
|
1 7 * * * root cd /usr/src/app && bundle exec ruby report_mailer.rb >> /var/log/cron.log 2>&1
|
||||||
Reference in New Issue
Block a user