Skip to content

Commit 891c54c

Browse files
committed
feat: 3.0.1
1 parent 2779955 commit 891c54c

File tree

5 files changed

+161
-1
lines changed

5 files changed

+161
-1
lines changed

.github/workflows/publish.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Publish Docker image
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
tags:
7+
- '**'
8+
workflow_dispatch:
9+
10+
jobs:
11+
push_to_registry:
12+
name: Push Docker image to Docker Hub
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Check out the repo
16+
uses: actions/checkout@v4
17+
- name: Log in to Docker Hub
18+
uses: docker/login-action@v3
19+
with:
20+
username: ${{ secrets.DOCKER_USERNAME }}
21+
password: ${{ secrets.DOCKER_PASSWORD }}
22+
- name: Extract metadata (tags, labels) for Docker
23+
id: meta
24+
uses: docker/metadata-action@v5
25+
with:
26+
images: scalified/certbot-cloudflare
27+
tags: |
28+
type=raw,value=latest
29+
type=semver,pattern={{version}}
30+
- name: Build and push Docker image
31+
uses: docker/build-push-action@v5
32+
with:
33+
context: .
34+
push: true
35+
tags: ${{ steps.meta.outputs.tags }}
36+
labels: ${{ steps.meta.outputs.labels }}
37+
38+

Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM scalified/cron:1.37.0
2+
3+
LABEL maintainer="Scalified <scalified@gmail.com>"
4+
5+
RUN apk add --update --no-cache certbot \
6+
certbot-dns-cloudflare \
7+
docker-cli
8+
9+
RUN echo "CERTBOT VERSIONS: $(apk list | grep certbot)"
10+
11+
COPY init.d/ /init.d/
12+
COPY usr/ /usr/
13+

README.md

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,54 @@
1-
# docker-certbot-cloudflare
1+
# Certbot Cloudflare Docker Image
2+
3+
[![Release](https://img.shields.io/github/v/release/Scalified/docker-certbot-cloudflare?style=flat-square)](https://github.com/Scalified/docker-certbot-cloudflare/releases/latest)
4+
[![Docker Pulls](https://img.shields.io/docker/pulls/scalified/certbot-cloudflare.svg)](https://hub.docker.com/r/scalified/certbot-cloudflare)
5+
[![License](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/Scalified/docker-certbot-cloudflare/blob/master/LICENSE)
6+
7+
## Overview
8+
9+
[**Alpine**](https://www.alpinelinux.org/) [**Docker**](https://www.docker.com/) image with [**Certbot**](https://certbot.eff.org/) preconfigured to autorenew SSL certificates
10+
using [**Cloudflare**](https://www.cloudflare.com) DNS. Built on top of the [**Scalified CRON**](https://github.com/Scalified/docker-cron) image
11+
12+
[**Certbot**](https://certbot.eff.org/) is used in `certonly` mode and runs with the `--keep-until-expiring` flag, which ensures that an existing certificate is reused until it is
13+
within 30 days of expiration. A CRON job is configured to run Certbot at container startup and once daily at night, helping to ensure that SSL certificates are always up to date
14+
15+
## Usage
16+
17+
1. Generate a [Cloudflare User API Token](https://developers.cloudflare.com/fundamentals/api/get-started/create-token/) with `Zone:DNS:Edit` permissions
18+
2. Save the generated token in a [Cloudflare credentials](https://certbot-dns-cloudflare.readthedocs.io/en/stable/#credentials) file
19+
3. Launch the `scalified/certbot-cloudflare` Docker image:
20+
21+
```bash
22+
docker run \
23+
--name certbot \
24+
-e CF_EMAIL="admin@example.com" \
25+
-e CF_CREDENTIALS_FILE="/etc/certbot/cloudflare.ini" \
26+
-e CF_PROPAGATION_SECONDS="60" \
27+
-e DOMAINS="*.example.com example.com" \
28+
-e LETSENCRYPT_DIR="/etc/letsencrypt" \
29+
-e DEPLOY_HOOK="docker exec nginx nginx -s reload" \
30+
-e CERTBOT_CRON_SCHEDULE="27 1 * * *" \
31+
-v ./cloudflare.ini:/etc/certbot/cloudflare.ini:ro \
32+
-v ./letsencrypt:/etc/letsencrypt \
33+
-v /var/run/docker.sock:/var/run/docker.sock \
34+
--detach \
35+
--restart always \
36+
scalified/certbot-cloudflare
37+
```
38+
39+
| Environment Variable | Description | Default Value |
40+
|-------------------------|-------------------------------------------------------------------------------------------------|-------------------------------|
41+
| `CF_EMAIL` | Email address associated with **Cloudflare** account | |
42+
| `CF_CREDENTIALS_FILE` | Path to the **Cloudflare** credentials file used for DNS authentication | `/etc/certbot/cloudflare.ini` |
43+
| `CF_PROPAGATION_SECODS` | Number of seconds to wait for DNS propagation before requesting validation from the ACME server | `60` |
44+
| `LETSENCRYPT_DIR` | Directory where Certbot stores the generated Let's Encrypt SSL certificates | `/etc/letsencrypt` |
45+
| `DOMAINS` | Space-separated list of domains for which SSL certificates should be generated | |
46+
| `DEPLOY_HOOK` | Shell command to run once per successfully issued certificate | |
47+
| `CERTBOT_CRON_SCHEDULE` | **CRON** expression that defines when to run the Certbot renewal | `27 1 * * *` |
48+
49+
## Scalified Links
50+
51+
* [Scalified](http://www.scalified.com)
52+
* [Scalified Official Facebook Page](https://www.facebook.com/scalified)
53+
* <a href="mailto:info@scalified.com?subject=[Docker Certbot Cloudflare]: Proposals And Suggestions">Scalified Support</a>
54+

init.d/certbot-crontab.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
3+
CERTBOT_CRON_SCHEDULE="${CERTBOT_CRON_SCHEDULE:-27 1 * * *}"
4+
5+
append_cron_schedule() {
6+
local schedule="$1"
7+
local line="$schedule certbot-renew"
8+
grep -qF "$line" $CRONTAB || echo "$line" >> $CRONTAB
9+
}
10+
11+
echo "INFO Certbot CRON schedule is: $CERTBOT_CRON_SCHEDULE"
12+
13+
append_cron_schedule "@reboot"
14+
append_cron_schedule "$CERTBOT_CRON_SCHEDULE"
15+

usr/local/bin/certbot-renew

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
CF_CREDENTIALS_FILE="${CF_CREDENTIALS_FILE:-/etc/certbot/cloudflare.ini}"
6+
CF_PROPAGATION_SECONDS="${CF_PROPAGATION_SECONDS:-60}"
7+
LETSENCRYPT_DIR="${LETSENCRYPT_DIR:-/etc/letsencrypt}"
8+
9+
shutdown() {
10+
kill -TERM 1
11+
exit 1
12+
}
13+
14+
if [ ! -f "$CF_CREDENTIALS_FILE" ]; then
15+
echo "ERROR $CF_CREDENTIALS_FILE file not found"
16+
shutdown
17+
fi
18+
19+
if [ -z "$CF_EMAIL" ]; then
20+
echo "ERROR 'CF_EMAIL' environment variable undefined"
21+
shutdown
22+
fi
23+
24+
if [ -z "$DOMAINS" ]; then
25+
echo "ERROR 'DOMAINS' environment variable undefined"
26+
shutdown
27+
fi
28+
29+
echo "INFO Starting SSL certificates check / renew..."
30+
certbot certonly \
31+
--dns-cloudflare \
32+
--dns-cloudflare-credentials "$CF_CREDENTIALS_FILE" \
33+
--dns-cloudflare-propagation-seconds "$CF_PROPAGATION_SECONDS" \
34+
--email "$CF_EMAIL" \
35+
--agree-tos \
36+
--no-eff-email \
37+
--keep-until-expiring \
38+
--deploy-hook "$DEPLOY_HOOK" \
39+
$(for domain in $DOMAINS; do echo "--domain $domain"; done)
40+
echo "INFO SSL certificates check / renew done"
41+

0 commit comments

Comments
 (0)