Skip to content

Commit

Permalink
Merge pull request #32 from hu3rror/memogram
Browse files Browse the repository at this point in the history
Memogram
  • Loading branch information
hu3rror authored May 19, 2024
2 parents 8b2d6b1 + 82fa386 commit 37a0dc1
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 11 deletions.
6 changes: 5 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# For Litestream
LITESTREAM_ACCESS_KEY_ID=000000001a2b3c40000000001
LITESTREAM_SECRET_ACCESS_KEY=K000ABCDEFGHiJkLmNoPqRsTuVwXyZ0
LITESTREAM_REPLICA_BUCKET=xxxxxxxxx
LITESTREAM_REPLICA_ENDPOINT=s3.us-west-000.backblazeb2.com
LITESTREAM_REPLICA_PATH=memos_prod.db
LITESTREAM_REPLICA_PATH=memos_prod.db
# For Memogram
MEMOGRAM_SERVER_ADDR=dns:localhost:5230
MEMOGRAM_BOT_TOKEN=your_telegram_bot_token
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

- name: Extract build args
id: keydb
uses: pozetroninc/github-action-get-latest-release@v0.7.0
uses: pozetroninc/github-action-get-latest-release@v0.8.0
with:
owner: usememos
repo: memos
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: get-build-stable-artifacts-with-memogram-and-push-image

on:
push:
paths:
- 'Dockerfile.memogram'
- 'scripts/run-memogram.sh'
workflow_dispatch:

jobs:
build-and-push-release-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Extract build args
id: keydb
uses: pozetroninc/github-action-get-latest-release@v0.8.0
with:
owner: usememos
repo: memos
excludes: prerelease, draft
token: ${{ github.token }}
- name: Login to Docker Hub
uses: docker/login-action@v3
if: github.event_name != 'pull_request'
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
hu3rror/memos-litestream
ghcr.io/hu3rror/memos-litestream
tags: |
type=raw,value=stable-memogram
type=semver,pattern={{version}},value=${{ steps.keydb.outputs.release }}-memogram
- name: Build and Push
id: docker_build
uses: docker/build-push-action@v5
with:
context: ./
file: ./Dockerfile.memogram
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ COPY --from=package /usr/local/bin/litestream /usr/local/bin/litestream
COPY etc/litestream.yml /etc/litestream.yml

# Copy startup script and make it executable.
COPY scripts/run.sh /usr/local/memos/run.sh
RUN chmod +x /usr/local/memos/run.sh
COPY scripts/run-memos-with-litestream.sh /usr/local/memos/run-memos-with-litestream.sh
RUN chmod +x /usr/local/memos/run-memos-with-litestream.sh

# Define ENV
ENV DB_PATH="/var/opt/memos/memos_prod.db"

# Run memos with litestream (Default WORKDIR is `/usr/local/memos/`)
CMD ["./run.sh"]
CMD ["./run-memos-with-litestream.sh"]
82 changes: 82 additions & 0 deletions Dockerfile.memogram
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Set the Litestream image tag
ARG LITESTREAM_IMAGE_TAG=0.3.13
# Set the Memos image tag
ARG MEMOS_IMAGE_TAG=0.22.0

# Build Litestream
FROM docker.io/litestream/litestream:${LITESTREAM_IMAGE_TAG} AS litestream_upstream
# Set the entry point to an empty array
ENTRYPOINT []

# Build Memos
FROM ghcr.io/usememos/memos:${MEMOS_IMAGE_TAG} AS memos_upstream
# Set the entry point to an empty array
ENTRYPOINT []

# Final image
FROM ubuntu:latest as final
# Set the working directory to /usr/local/memos
WORKDIR /usr/local/memos

# Update apt and install necessary software
RUN apt-get update && apt-get install -y wget tzdata tmux curl bash
# Set the timezone to UTC
ENV TZ="UTC"

# Copy Memos to /usr/local/memos
COPY --from=memos_upstream /usr/local/memos/ /usr/local/memos/

# Copy Litestream to /usr/local/bin
COPY --from=litestream_upstream /usr/local/bin/litestream /usr/local/bin/litestream

# Set the target architecture
ARG TARGETARCH

# Download Memogram
ENV MEMOGRAM_TAG=0.1.1
RUN wget https://github.com/usememos/telegram-integration/releases/download/v${MEMOGRAM_TAG}/memogram_v${MEMOGRAM_TAG}_linux_${TARGETARCH}.tar.gz && \
tar -xvf memogram_v${MEMOGRAM_TAG}_linux_${TARGETARCH}.tar.gz && \
rm memogram_v${MEMOGRAM_TAG}_linux_${TARGETARCH}.tar.gz README.md && \
chown root:root /usr/local/memos/memogram && \
chmod +x /usr/local/memos/memogram

# Download overmind
ENV OVERMIND_VERSION=2.5.1
RUN wget https://github.com/DarthSim/overmind/releases/download/v${OVERMIND_VERSION}/overmind-v${OVERMIND_VERSION}-linux-${TARGETARCH}.gz && \
gzip -d overmind-v${OVERMIND_VERSION}-linux-${TARGETARCH}.gz && \
mv overmind-v${OVERMIND_VERSION}-linux-${TARGETARCH} overmind && \
chmod +x overmind

# Copy Memogram environment file
COPY etc/memogram.env /usr/local/memos/.env

# Copy Litestream global configuration file
COPY etc/litestream.yml /etc/litestream.yml

# Copy memos script and make it executable
COPY scripts/run-memos-with-litestream.sh /usr/local/memos/run-memos-with-litestream.sh
RUN chmod +x /usr/local/memos/run-memos-with-litestream.sh

# Copy Memogram script and make it executable
COPY scripts/run-memogram.sh /usr/local/memos/run-memogram.sh
RUN chmod +x /usr/local/memos/run-memogram.sh

# Copy overmind configuration file
COPY etc/Procfile /usr/local/memos/Procfile

# Define environment variables
ENV DB_PATH="/var/opt/memos/memos_prod.db"

# Expose port 5230
EXPOSE 5230

# Create a directory to store data, which can be referenced as the mounting point
RUN mkdir -p /var/opt/memos
VOLUME /var/opt/memos

# Set Memos mode to "prod" and port to 5230
ENV MEMOS_MODE="prod"
ENV MEMOS_PORT="5230"

# Run Memos with Litestream (Default WORKDIR is `/usr/local/memos/`)
CMD ["./overmind", "start", "-f", "/usr/local/memos/Procfile"]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ This endeavor is grounded in [usememos/memos](https://github.com/usememos/memos)

### RUN

> The image supports linux/amd64, linux/arm64, linux/arm/v7
> The image supports linux/amd64, linux/arm64
>
> `stable`, `latest`, `test` are accessible docker image tags.
> `stable`, `latest`, `test`, `stable-memogram` are accessible docker image tags. `stable-memogram` integrates the function of being sent to Memos by telegram bot, you need to customize the MEMOGRAM_BOT_TOKEN environment variable before using it, go to https://github.com/usememos/telegram-integration to get more details.
!!! **Ensure to modify the environment variables before execution** !!!

Expand Down
4 changes: 2 additions & 2 deletions README_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

### 运行

> 该镜像支持 linux/amd64、linux/arm64、linux/arm/v7
> 该镜像支持 linux/amd64、linux/arm64
>
> `stable``latest``test` 是可用的 Docker 镜像标签
> `stable``latest``test``stable-memogram` 是可用的 Docker 镜像标签,其中 `stable-memogram` 集成了 telegram bot 发送到 Memos 功能,使用前需要自定义 MEMOGRAM_BOT_TOKEN 环境变量,详情查看 https://github.com/usememos/telegram-integration
!!! **在运行之前务必编辑环境变量** !!!

Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ services:
- LITESTREAM_REPLICA_ENDPOINT=s3.us-west-000.backblazeb2.com # change to your litestream endpoint url
- LITESTREAM_ACCESS_KEY_ID=000000001a2b3c40000000001 # Your s3/b2 access-key-id
- LITESTREAM_SECRET_ACCESS_KEY=K000ABCDEFGHiJkLmNoPqRsTuVwXyZ0 # Your s3/b2 secret-access-key
- MEMOGRAM_SERVER_ADDR=dns:localhost:5230 # It's better not to change
- MEMOGRAM_BOT_TOKEN=0000000000000000000000000000000000000000 # Your telegram bot token
# env_file:
# - .env
2 changes: 2 additions & 0 deletions etc/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
memos: ./run-memos-with-litestream.sh
memogram: sleep 5 && ./run-memogram.sh
2 changes: 2 additions & 0 deletions etc/memogram.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SERVER_ADDR=dns:localhost:5230
BOT_TOKEN=<MEMOGRAM_BOT_TOKEN>
17 changes: 17 additions & 0 deletions scripts/run-memogram.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh
set -e

# Replace MEMOGRAM_BOT_TOKEN in .env
if [ -f "./memogram" ] && [ -f "./.env" ] && [ -n "$MEMOGRAM_BOT_TOKEN" ]; then
# Replace MEMOGRAM_BOT_TOKEN in .env
sed -i 's/<MEMOGRAM_BOT_TOKEN>/'"$MEMOGRAM_BOT_TOKEN"'/g' ./.env

# Replace MEMOS_PORT in .env
if [ "$MEMOS_PORT" != "5230" ]; then
sed -i 's/5230/'"$MEMOS_PORT"'/g' ./.env
fi

# Run memogram
echo "Starting memogram service."
exec ./memogram
fi
3 changes: 1 addition & 2 deletions scripts/run.sh → scripts/run-memos-with-litestream.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ else
echo "Finished restoring the database."
fi

echo "Starting litestream & memos service."

# Run litestream with your app as the subprocess.
echo "Starting litestream & memos service."
exec litestream replicate -exec "./memos"

0 comments on commit 37a0dc1

Please sign in to comment.