Compare commits

..

4 Commits

Author SHA1 Message Date
4b822855a7
Optimize Dokerfile 2023-01-12 13:05:38 +03:00
f4ce9083ae
Upload test github action 2023-01-12 12:20:39 +03:00
5b808df1c2
Add docker support 2023-01-12 12:06:24 +03:00
bc0b2afb38
Rename cron file and fix requirements 2023-01-12 10:39:00 +03:00
6 changed files with 79 additions and 4 deletions

View File

@ -0,0 +1,41 @@
name: Create and publish a Docker image
on:
push:
branches: ['main']
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

18
Dockerfile Normal file
View File

@ -0,0 +1,18 @@
FROM python:3.11.1-alpine3.17
LABEL Maintainer="serega404"
WORKDIR /app
COPY ./requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
COPY crontab /etc/cron.d/crontab
RUN chmod 0644 /etc/cron.d/crontab
COPY main.py main.py
RUN /usr/bin/crontab /etc/cron.d/crontab
# run crond as main process of container
CMD ["/usr/sbin/crond", "-f"]

View File

@ -20,6 +20,19 @@
<img src="./grafana.png" width="400" height="300" />
### Запуск в Docker
``` Docker
docker run -d --name MetricAliexpressExchangeRate \
--restart=always \
-e METRIC_SERVER_URL='http(s)://<IP_ADDR>:<PORT>/' \
ghcr.io/serega404/metricaliexpressexchangerate:main
```
#### Дополнительные переменные среды:
* `CBRF_APISITE_URL`
* `ALI1USD_PAGE_URL`
### Библиотеки
* [BeautifulSoup](https://www.crummy.com/software/BeautifulSoup/)

1
crontab Normal file
View File

@ -0,0 +1 @@
*/10 * * * * python3 /app/main.py >> /tmp/out.log

View File

@ -1,11 +1,11 @@
import requests, re, json
import requests, re, json, os
from bs4 import BeautifulSoup
# Config
Ali1USDPageURL = 'https://aliexpress.ru/item/32892046259.html'
CBRFApiSiteURL = 'https://www.cbr-xml-daily.ru/daily_json.js'
MetricServerURL = 'http://192.168.0.100:8428/'
Ali1USDPageURL = os.environ.get('ALI1USD_PAGE_URL', 'https://aliexpress.ru/item/32892046259.html')
CBRFApiSiteURL = os.environ.get('CBRF_APISITE_URL', 'https://www.cbr-xml-daily.ru/daily_json.js')
MetricServerURL = os.environ.get('METRIC_SERVER_URL', 'http://192.168.0.100:8428/')
KursAli = ""
KursCBRF = ""

2
requirements.txt Normal file
View File

@ -0,0 +1,2 @@
requests
beautifulsoup4