From 4a2d0f2a70fafbafca5ae9522023e36c06243abf Mon Sep 17 00:00:00 2001 From: metowolf Date: Tue, 18 Jul 2023 13:02:45 +0800 Subject: [PATCH] update dockerfile --- .dockerignore | 6 +++++ .github/workflows/release.yml | 19 +++++++++++-- Dockerfile | 51 +++++++++++++++++++++++++++++++++++ src/plugins/vcard-ext.js | 4 +-- 4 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..b9769102 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +node_modules +temp +public +*.zip +.DS_Store +radicale diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0c2272b2..b2e2bbd8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,7 +5,7 @@ on: branches: [ "master" ] workflow_dispatch: jobs: - build: + release-build: runs-on: ubuntu-latest steps: - name: Checkout @@ -17,4 +17,19 @@ jobs: yarn install yarn test yarn build - gh release create $(date +'%Y%m%d%H%M%S')-$(git log --format=%h -1) public/* \ No newline at end of file + gh release create $(date +'%Y%m%d%H%M%S')-$(git log --format=%h -1) public/* + docker-build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Build image and push + env: + DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + IMAGE_VERSION=`cat package.json | jq -r '.version'` + echo $DOCKER_TOKEN | docker login -u metowolf --password-stdin + docker build -t metowolf/vcards:$IMAGE_VERSION --squash --push . + echo $GITHUB_TOKEN | docker login ghcr.io -u metowolf --password-stdin + docker build -t ghcr.io/metowolf/vcards:$IMAGE_VERSION --squash --push . \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..81a6d9bf --- /dev/null +++ b/Dockerfile @@ -0,0 +1,51 @@ +FROM node as builder + +COPY . /app +WORKDIR /app +RUN yarn && yarn radicale + + +FROM alpine + +RUN apk add --no-cache \ + radicale \ + && rm -rf /var/cache/apk/* \ + \ + && { \ + echo '[root]'; \ + echo 'user: .+'; \ + echo 'collection:'; \ + echo 'permissions: R'; \ + echo; \ + echo '[principal]'; \ + echo 'user: .+'; \ + echo 'collection: {user}'; \ + echo 'permissions: R'; \ + echo; \ + echo '[collections]'; \ + echo 'user: .+'; \ + echo 'collection: {user}/[^/]+'; \ + echo 'permissions: rR'; \ + } > /etc/radicale/rights \ + \ + && { \ + echo '[server]'; \ + echo 'hosts = 0.0.0.0:5232, [::]:5232'; \ + echo; \ + echo '[web]'; \ + echo 'type = none'; \ + echo; \ + echo '[storage]'; \ + echo 'type = multifilesystem'; \ + echo 'filesystem_folder = /app/vcards'; \ + echo; \ + echo '[rights]'; \ + echo 'type = from_file'; \ + echo 'file = /etc/radicale/rights'; \ + } > /etc/radicale/config + +COPY --from=builder /app/radicale/ /app/vcards/collection-root/cn/ + +EXPOSE 5232 + +CMD ["radicale"] \ No newline at end of file diff --git a/src/plugins/vcard-ext.js b/src/plugins/vcard-ext.js index 7b813c94..fc3ab73e 100644 --- a/src/plugins/vcard-ext.js +++ b/src/plugins/vcard-ext.js @@ -19,8 +19,8 @@ const plugin = (file, _, cb) => { } vCard.photo.embedFromFile(path.replace('.yaml', '.png')) - let lastYamlChangeDateString = execSync('git log -1 --pretty="format:%ci" ' + path).toString().trim().replace(/\s\+\d+/, '') - let lastPngChangeDateString = execSync('git log -1 --pretty="format:%ci" ' + path.replace('.yaml', '.png')).toString().trim().replace(/\s\+\d+/, '') + let lastYamlChangeDateString = execSync(`git log -1 --pretty="format:%ci" "${path}"`).toString().trim().replace(/\s\+\d+/, '') + let lastPngChangeDateString = execSync(`git log -1 --pretty="format:%ci" "${path.replace('yaml', 'png')}"`).toString().trim().replace(/\s\+\d+/, '') let rev = new Date(Math.max(new Date(lastYamlChangeDateString), new Date(lastPngChangeDateString))).toISOString()