Skip to content

Commit

Permalink
Merge pull request #57 from smkent/docker
Browse files Browse the repository at this point in the history
Add Docker container and example docker-compose configuration
  • Loading branch information
smkent authored Oct 27, 2022
2 parents ddfc467 + 942972b commit ba08308
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 7 deletions.
1 change: 1 addition & 0 deletions .dockerignore
65 changes: 65 additions & 0 deletions .github/workflows/container.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
name: Build

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
RELEASE_PYTHON_VERSION: "3.10"
RELEASE_POETRY_VERSION: "1.2"

on:
pull_request:
push:
branches:
- '*'
tags:
- 'v*'
workflow_dispatch:

jobs:
Container:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: 💾 Check out repository
uses: actions/checkout@v3

- name: 🔑 Log in to the container registry
uses: docker/login-action@v2.1.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: 📡 Collect image metadata
id: meta
uses: docker/metadata-action@v4.1.1
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }}
type=edge,branch=main
- name: 🐍 Set up Python project with Poetry
uses: ./.github/workflows/actions/python-poetry
with:
python_version: ${{ env.RELEASE_PYTHON_VERSION }}
poetry_version: ${{ env.RELEASE_POETRY_VERSION }}

- name: 🔥 Test
run: poetry run poe test

- name: 📦 Build and publish container image
uses: docker/build-push-action@v3.2.0
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.egg-info/
*.pyc
.coverage
.git
.pytest_cache/
.pytest_coverage.xml
.pytest_results.xml
Expand Down
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM python:3-alpine
ENV CRON_SCHEDULE "5 2 * * *"
ENV SMTPHOST=
ENV SAFEWAY_ACCOUNT_USERNAME=
ENV SAFEWAY_ACCOUNT_PASSWORD=
ENV SAFEWAY_ACCOUNT_MAIL_FROM=
ENV SAFEWAY_ACCOUNT_MAIL_TO=

RUN apk add --no-cache tini
COPY docker/entrypoint /

COPY . /python-build
RUN python3 -m pip install /python-build && rm -rf /python-build

ENTRYPOINT ["/sbin/tini", "--"]
CMD ["/entrypoint"]
50 changes: 43 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,59 @@
and attempt to select all of the "Safeway for U" electronic coupons on the site
so they don't have to each be clicked manually.

For best results, run this program once a day or so with a cron daemon.
## Installation and usage with Docker

A Docker container is provided which runs safeway-coupons with cron. The cron
schedule and your Safeway account details should be configured using environment
variables.

Example `docker-compose.yaml`:

```yaml
version: "3.7"

services:
safeway-coupons:
image: ghcr.io/smkent/safeway-coupons:latest
environment:
CRON_SCHEDULE: "0 2 * * *" # Run at 2:00 AM each day
SMTPHOST: your.smtp.host
SAFEWAY_ACCOUNT_USERNAME: your.safeway.account.email@example.com
SAFEWAY_ACCOUNT_PASSWORD: very_secret
SAFEWAY_ACCOUNT_MAIL_FROM: your.email@example.com
SAFEWAY_ACCOUNT_MAIL_TO: your.email@example.com
restart: unless-stopped
```
## Installation
Start the container by running:
[safeway-coupons is available on PyPI][pypi]:
```console
docker-compose up -d
```

Debugging information can be viewed in the container log:

```console
docker-compose logs -f
```

## Installation from PyPI

[safeway-coupons is available on PyPI][pypi]:

```console
pip install safeway-coupons
```

For email support, `sendmail` is needed.
`sendmail` is needed for email support.

## Usage
For best results, run this program once a day or so with a cron daemon.

### Usage

For full usage options, run

```sh
```console
safeway-coupons --help
```

Expand Down Expand Up @@ -67,7 +103,7 @@ notify = your.email@example.com ; optional
Provide the path to your config file using the `-c` or `--accounts-config`
option:

```sh
```console
safeway-coupons -c path/to/config/file
```

Expand Down
13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: "3.7"

services:
safeway-coupons:
image: ghcr.io/smkent/safeway-coupons:latest
environment:
CRON_SCHEDULE: "0 2 * * *"
SMTPHOST: your.smtp.host
SAFEWAY_ACCOUNT_USERNAME: your.safeway.account.email@example.com
SAFEWAY_ACCOUNT_PASSWORD: very_secret
SAFEWAY_ACCOUNT_MAIL_FROM: your.email@example.com
SAFEWAY_ACCOUNT_MAIL_TO: your.email@example.com
restart: unless-stopped
26 changes: 26 additions & 0 deletions docker/entrypoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh

set -ex

if [ -z "${SAFEWAY_ACCOUNT_MAIL_TO}" ] \
&& [ -n "${SAFEWAY_ACCOUNT_USERNAME}" ]; then
export SAFEWAY_ACCOUNT_MAIL_TO="${SAFEWAY_ACCOUNT_USERNAME}"
fi

if [ -n "${SAFEWAY_ACCOUNT_MAIL_FROM}" ]; then
export MAILFROM="${SAFEWAY_ACCOUNT_MAIL_FROM}"
fi
if [ -n "${SAFEWAY_ACCOUNT_MAIL_TO}" ]; then
export MAILFROM="${SAFEWAY_ACCOUNT_MAIL_TO}"
fi

mkdir /etc/cron.d
(
echo "${CRON_SCHEDULE?} safeway-coupons >/proc/1/fd/1 2>/proc/1/fd/2"
) > /var/spool/cron/crontabs/root

env | grep -vie 'password' | grep -e '^SAFEWAY_' -e '^SMTPHOST='

crontab -l

exec crond -f -d 8

0 comments on commit ba08308

Please sign in to comment.