Skip to content

Commit d475c44

Browse files
Merge pull request #8 from auth-it-center/develop
Update codimd to latest upstream
2 parents 3f5bd42 + b904416 commit d475c44

26 files changed

Lines changed: 388 additions & 106 deletions

.github/workflows/build.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
name: 'Test and Build'
22

33
on:
4-
push:
5-
pull_request:
64
workflow_dispatch:
75

86
jobs:

.github/workflows/push-image.yml

Lines changed: 14 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,15 @@ on:
1515
default: 'hackmdio/buildpack:16.20.2-35fe7e39'
1616

1717
env:
18-
REGISTRY_IMAGE: hackmdio/hackmd
18+
REGISTRY_IMAGE: demo-images/codimd
1919

2020
jobs:
2121
build:
2222
runs-on: ubuntu-latest
23-
strategy:
24-
fail-fast: false
25-
matrix:
26-
platform:
27-
- linux/amd64
28-
- linux/arm64
2923
steps:
3024
-
3125
name: Prepare
32-
run: |
33-
platform=${{ matrix.platform }}
34-
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
26+
run: echo "PLATFORM_PAIR=linux-amd64" >> $GITHUB_ENV
3527
-
3628
name: Checkout
3729
uses: actions/checkout@v4
@@ -51,73 +43,25 @@ jobs:
5143
name: Login to Docker Hub
5244
uses: docker/login-action@v3
5345
with:
54-
username: ${{ secrets.DOCKERHUB_USERNAME }}
55-
password: ${{ secrets.DOCKERHUB_TOKEN }}
46+
# username: ${{ secrets.DOCKERHUB_USERNAME }}
47+
# password: ${{ secrets.DOCKERHUB_TOKEN }}
48+
username: ${{ secrets.NEXUS_USERNAME }}
49+
password: ${{ secrets.NEXUS_PASSWORD }}
50+
registry: ${{ secrets.NEXUS_REGISTRY }}
5651
-
57-
name: Build and push by digest
52+
name: Build and push
5853
id: build
5954
uses: docker/build-push-action@v5
6055
with:
6156
context: .
6257
file: ./deployments/Dockerfile
63-
platforms: ${{ matrix.platform }}
58+
platforms: linux/amd64
6459
labels: ${{ steps.meta.outputs.labels }}
65-
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
60+
tags: |
61+
${{ secrets.NEXUS_REGISTRY }}/${{ env.REGISTRY_IMAGE }}:latest
62+
${{ secrets.NEXUS_REGISTRY }}/${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
63+
6664
build-args: |
6765
RUNTIME=${{ github.event.inputs.runtime || 'hackmdio/runtime:16.20.2-35fe7e39' }}
6866
BUILDPACK=${{ github.event.inputs.buildpack || 'hackmdio/buildpack:16.20.2-35fe7e39' }}
69-
-
70-
name: Export digest
71-
run: |
72-
mkdir -p /tmp/digests
73-
digest="${{ steps.build.outputs.digest }}"
74-
touch "/tmp/digests/${digest#sha256:}"
75-
-
76-
name: Upload digest
77-
uses: actions/upload-artifact@v4
78-
with:
79-
name: digests-${{ env.PLATFORM_PAIR }}
80-
path: /tmp/digests/*
81-
if-no-files-found: error
82-
retention-days: 1
83-
84-
merge:
85-
runs-on: ubuntu-latest
86-
needs:
87-
- build
88-
steps:
89-
-
90-
name: Download digests
91-
uses: actions/download-artifact@v4
92-
with:
93-
path: /tmp/digests
94-
pattern: digests-*
95-
merge-multiple: true
96-
-
97-
name: Set up Docker Buildx
98-
uses: docker/setup-buildx-action@v3
99-
-
100-
name: Docker meta
101-
id: meta
102-
uses: docker/metadata-action@v5
103-
with:
104-
images: ${{ env.REGISTRY_IMAGE }}
105-
tags: |
106-
type=match,pattern=\d.\d.\d
107-
type=sha,prefix=
108-
-
109-
name: Login to Docker Hub
110-
uses: docker/login-action@v3
111-
with:
112-
username: ${{ secrets.DOCKERHUB_USERNAME }}
113-
password: ${{ secrets.DOCKERHUB_TOKEN }}
114-
-
115-
name: Create manifest list and push
116-
working-directory: /tmp/digests
117-
run: |
118-
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
119-
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
120-
-
121-
name: Inspect image
122-
run: |
123-
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
67+
push: true
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Build and Push k8s Image
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
runtime:
7+
description: 'Runtime image'
8+
required: true
9+
default: 'hackmdio/runtime:16.20.2-35fe7e39'
10+
buildpack:
11+
description: 'Buildpack image'
12+
required: true
13+
default: 'hackmdio/buildpack:16.20.2-35fe7e39'
14+
release:
15+
types: [published]
16+
17+
env:
18+
REGISTRY_IMAGE: demo-images/codimd
19+
jobs:
20+
build-and-push:
21+
if: startsWith(github.event.release.tag_name, 'k8s-v')
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- name: Checkout source
26+
uses: actions/checkout@v3
27+
with:
28+
ref: k8s
29+
30+
- name: Set up Docker Buildx
31+
uses: docker/setup-buildx-action@v3
32+
33+
- name: Log in to Docker registry
34+
uses: docker/login-action@v3
35+
with:
36+
username: ${{ secrets.NEXUS_USERNAME }}
37+
password: ${{ secrets.NEXUS_PASSWORD }}
38+
registry: ${{ secrets.NEXUS_REGISTRY }}
39+
40+
- name: Determine tag
41+
id: tag
42+
run: |
43+
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
44+
echo "IMAGETAG=k8s-${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
45+
else
46+
echo "IMAGETAG=k8s-latest" >> $GITHUB_OUTPUT
47+
fi
48+
49+
- name: Build and push Docker image
50+
uses: docker/build-push-action@v5
51+
with:
52+
context: .
53+
file: deployments/Dockerfile
54+
push: true
55+
tags: ${{ secrets.NEXUS_REGISTRY }}/${{ env.REGISTRY_IMAGE }}:${{ steps.tag.outputs.IMAGETAG }}
56+
build-args: |
57+
RUNTIME=${{ github.event.inputs.runtime || 'hackmdio/runtime:16.20.2-35fe7e39' }}
58+
BUILDPACK=${{ github.event.inputs.buildpack || 'hackmdio/buildpack:16.20.2-35fe7e39' }}

.github/workflows/test.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
name: Hello world test action
3+
4+
on:
5+
workflow_dispatch:
6+
7+
jobs:
8+
say-hello:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v2
14+
15+
- name: Hello world
16+
run: echo "Hello world"

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
CodiMD
22
===
33

4+
### This is a fork of the original CodiMD project. The original project can be found [here](https://github.com/hackmdio/codimd).
5+
46
[![build status][build-image]][build-url]
7+
58
[![version][github-version-badge]][github-release-page]
69
[![Gitter][gitter-image]][gitter-url]
710
[![Matrix][matrix-image]][matrix-url]

app.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "CodiMD",
3-
"description": "Realtime collaborative markdown notes on all platforms",
2+
"name": "AuthMD",
3+
"description": "Fork of CodiMD",
44
"keywords": [
55
"Collaborative",
66
"Markdown",

bin/checkusers.sh

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/bin/bash
2+
# The script uses Cronjob to run once a day to check for expired users
3+
# It is vital to have RUN env > /etc/environment in Dockerfile so that
4+
# cronjob can have access to env variables from docker
5+
. /home/hackmd/cron.env
6+
UPLOADS_DIR="/home/hackmd/app/public/uploads"
7+
TRASH_DIR="/home/hackmd/trash"
8+
9+
isActive() {
10+
if ! ldapres=$(ldapsearch -x -H $CMD_LDAP_URL -D "$CMD_LDAP_BINDDN" -w $CMD_LDAP_BINDCREDENTIALS -b $CMD_LDAP_SEARCHBASE $query 2>/dev/null); then
11+
echo "Ldap is DOWN. Exiting..."
12+
exit 1
13+
fi
14+
if echo "$ldapres" | grep -q -e "^uid:"; then
15+
return 0
16+
else
17+
return 1
18+
fi
19+
}
20+
21+
deleteUser(){
22+
# Deleting users from postgres database
23+
local profileid="$1"
24+
psql $CMD_DB_URL <<-SQL
25+
DELETE FROM "Users" WHERE profileid = '${profileid}';
26+
SQL
27+
}
28+
29+
deleteNotes(){
30+
# Deleting all user's notes from postgres database and moving them to
31+
# trash can
32+
shortids=$(psql $CMD_DB_URL -At<<-SQL
33+
SELECT shortid FROM "Notes" where "ownerId" = '${id}';
34+
SQL
35+
)
36+
while IFS=' ' read shortid; do
37+
title=$(psql $CMD_DB_URL -At<<-SQL
38+
SELECT title FROM "Notes" where shortid = '${shortid}';
39+
SQL
40+
)
41+
safe_title=$(echo "$title" | tr -cd '[:alnum:]._-')
42+
filename="${USER_TRASH_DIR}/${safe_title}.md"
43+
44+
content=$(psql $CMD_DB_URL -At<<-SQL
45+
SELECT content FROM "Notes" WHERE shortid = '${shortid}';
46+
SQL
47+
)
48+
49+
echo "$content" > "$filename"
50+
done<<<"$shortids"
51+
52+
psql $CMD_DB_URL <<-SQL
53+
DELETE FROM "Notes" where "ownerId" = '${id}';
54+
SQL
55+
}
56+
57+
deleteFiles(){
58+
# Deleting all user's uploads from location /home/hackmd/app/public/uploads
59+
# The files are saved as upload_{user.id}_{random letters}.{jpg,png,...}
60+
find $UPLOADS_DIR -type f -name "upload_${id}_*" -exec mv {} "$USER_TRASH_DIR" \; 2>&1
61+
}
62+
63+
actuallyDeleteFiles(){
64+
# Deleting all user's uploads from location /home/hackmd/app/public/uploads
65+
# The files are saved as upload_{user.id}_{random letters}.{jpg,png,...}
66+
67+
echo "Removing old trash files"
68+
find $TRASH_DIR -mindepth 1 -maxdepth 1 -type d -mtime +90 -exec rm -rf {} \; 2>&1
69+
}
70+
71+
# Write down the date-time
72+
date
73+
# Removing old trash files
74+
actuallyDeleteFiles
75+
allusers=$(psql $CMD_DB_URL -t -c 'SELECT profileid FROM "Users";')
76+
if [ -z "$allusers" ]; then
77+
echo "Ha Ha nothing to delete"
78+
exit
79+
fi
80+
while IFS=' ' read -r username; do
81+
# Extracting the username (removing LDAP- prefix)
82+
uid=$(echo $username | cut -d '-' -f2)
83+
# Creating the ldap search query
84+
query=$(echo $CMD_LDAP_SEARCHFILTER | sed "s#{{username}}#${uid}#")
85+
id=$(psql $CMD_DB_URL -t -A <<-SQL
86+
SELECT id FROM "Users" WHERE profileid = '${username}';
87+
SQL
88+
)
89+
# Check if the user exists in the ldap as active user
90+
if isActive; then
91+
echo "The account $uid is active"
92+
else
93+
echo "The account $uid must be destroyed"
94+
# This will be the user specific trash can
95+
USER_TRASH_DIR=${TRASH_DIR}/${uid}
96+
echo "Moving to Trash ${USER_TRASH_DIR}..."
97+
mkdir -p $USER_TRASH_DIR
98+
# These functions move uploads and notes to trash can
99+
# and delete them permanently after 90 days
100+
deleteUser $username
101+
deleteNotes
102+
deleteFiles
103+
104+
fi
105+
done <<< "$allusers"

0 commit comments

Comments
 (0)