Skip to content

Commit

Permalink
doc: add docker compose file
Browse files Browse the repository at this point in the history
  • Loading branch information
Cnily03 committed Mar 14, 2024
1 parent 31ebfa1 commit 619ff99
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 9 deletions.
16 changes: 11 additions & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,19 @@ jobs:
- uses: actions/checkout@v4
- name: Build and Publish Docker Image
run: |
tag=$(echo ${{ github.ref }} | sed 's/refs\/tags\///')
if [[ $tag == v[0-9]* ]]; then
tag=$(echo $tag | sed 's/v//')
tag="$(echo ${{ github.ref }} | sed 's/refs\/tags\///')"
if [[ "$tag" =~ ^v[0-9]* ]]; then
version="$(echo $tag | sed 's/v//')"
else
version="$tag"
fi
docker build -t ${{ vars.DOCKER_HUB_USERNAME }}/ssl-autoupdater:$tag .
docker build -t "${{ vars.DOCKER_HUB_USERNAME }}/ssl-autoupdater:$version" .
docker login -u ${{ vars.DOCKER_HUB_USERNAME }} -p ${{ secrets.DOCKER_HUB_TOKEN }}
docker push ${{ vars.DOCKER_HUB_USERNAME }}/ssl-autoupdater:$tag
docker push "${{ vars.DOCKER_HUB_USERNAME }}/ssl-autoupdater:$version"
if [[ "$tag" == "$(git describe --tags --abbrev=0)" ]]; then
docker tag "${{ vars.DOCKER_HUB_USERNAME }}/ssl-autoupdater:$version" "${{ vars.DOCKER_HUB_USERNAME }}/ssl-autoupdater:latest"
docker push "${{ vars.DOCKER_HUB_USERNAME }}/ssl-autoupdater:latest"
fi
npm:
runs-on: 'ubuntu-latest'
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ FROM node:20.11.0
COPY . /app
RUN mkdir -p /app/data
COPY ./config.js /app/data/config.js
RUN mkdir -p /app/data/logs

USER root
WORKDIR /app
RUN npm install && npm run build

ENTRYPOINT [ "npm", "run", "docker" ]
ENTRYPOINT [ "npm", "run", "docker-log" ]
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,16 @@ Pull `cnily03/ssl-autoupdater` from Docker Hub
docker run -itd \
-v /path/to/your/config.js:/app/data/config.js \
-v ~/.acme.sh:/root/.acme.sh \
--restart=always \
--restart=unless-stopped \
--name ssl-autoupdater \
cnily03/ssl-autoupdater
```

> [!TIP]
> Docker compose file is also provided in the repository.
> Edit it according to annotations in the file.
> Then run `docker compose up -d` to start the service.
Replace `/path/to/your/config.js` with your own configuration file.

Or you can mount the whole directory to `/app/data/` to make it easier to manage.
Expand Down
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3'

services:
ssl-autoupdater:
image: cnily03/ssl-autoupdater
container_name: ssl-autoupdater
tty: true
environment:
- TZ=Asia/Shanghai
volumes:
# Make directory `data` in the same directory as your docker-compose.yml file
# Create your configuration file in data directory
- ./data:/app/data
- ~/.acme.sh:/root/.acme.sh
restart: unless-stopped
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"compile-template": "node compile-template.js",
"build": "rm -rf dist/* dist/.[!.]* dist/..?* && tsc && tsc-alias && npm run compile-template",
"test": "npm run build && node test/index.js",
"docker": "node test/docker.js"
"docker": "node test/docker.js",
"docker-log": "mkdir -p /app/data/logs && node test/docker.js | tee /app/data/logs/$(date +\"%Y%m%d_%H%M%S\").log"
},
"keywords": ["auto", "SSL", "update"],
"author": "Cnily03",
Expand Down
11 changes: 10 additions & 1 deletion src/components/output.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import { Session } from "@/components/session"
import "colors"

const date_string = () => new Date().toLocaleString().replace(/\/(\d)([^\d])/, "/0$1$2").replace(/\/(\d)([^\d])/, "/0$1$2").replace(/\//g, "-")
const date_string = () => {
let date = new Date()
let year = date.getFullYear()
let month = (date.getMonth() + 1).toString().padStart(2, "0")
let day = date.getDate().toString().padStart(2, "0")
let hours = date.getHours().toString().padStart(2, "0")
let minutes = date.getMinutes().toString().padStart(2, "0")
let seconds = date.getSeconds().toString().padStart(2, "0")
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
}

export type OutputConstructor = new (session: Session, identifier?: string) => Output

Expand Down
10 changes: 10 additions & 0 deletions test/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ if (!fs.existsSync(CONF_PATH)) {
console.error("Config file not found at " + CONF_PATH)
process.exit(1)
}

let is_watch = false

// const CONFIG = require("../config.js")
const CONFIG = require(CONF_PATH)

Expand Down Expand Up @@ -55,11 +58,18 @@ if (CONFIG.qcloud.enable) {
if (CONFIG.mailserver.enable) opts.mailer = new autossl.MailSender(mailOpts())
const QCloudUpdater = new autossl.updater.QCloud(CONFIG.qcloud.secretId, CONFIG.qcloud.secretKey, opts)
QCloudUpdater.watch()
is_watch = true
}

if (CONFIG.qiniu.enable) {
let opts = QiniuBaseOpts()
if (CONFIG.mailserver.enable) opts.mailer = new autossl.MailSender(mailOpts())
const QiniuUpdater = new autossl.updater.Qiniu(CONFIG.qiniu.accessKey, CONFIG.qiniu.secretKey, opts)
QiniuUpdater.watch()
is_watch = true
}

if (!is_watch) {
console.log("No updater enabled. Please stop the container.")
process.stdin.resume();
}

0 comments on commit 619ff99

Please sign in to comment.