diff --git a/.example.env b/.example.env deleted file mode 100644 index b4e7414..0000000 --- a/.example.env +++ /dev/null @@ -1,2 +0,0 @@ -TELEGRAM_BOT_TOKEN=test -OWNER_CHAT_ID=123 diff --git a/.gitignore b/.gitignore index 3ad1afd..56407b5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -.idea/ -.env +.idea +vendor +docker-compose.override.yml diff --git a/Makefile b/Makefile deleted file mode 100644 index b7f9060..0000000 --- a/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -all: build - -.PHONY: build -build: modules - CGO_ENABLED=0 go build -o ./bin/anon3anon ./cmd/anon3anon - -.PHONY: modules -modules: - go mod tidy diff --git a/README.md b/README.md index 28ff7ed..d8eac5b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,52 @@ # anon3anon Telegram bot for anonymous messages 🎭✨ + +## Building for local development + +Prerequisites: + +1. git +2. docker + +Firstly, clone the repository: + +```shell +git clone git@github.com:nightnoryu/anon3anon.git +``` + +Then build the binary: + +```shell +./bin/a3abrewkit build +``` + +This script will download a [brewkit](https://github.com/ispringtech/brewkit) binary and put it in the `bin` directory of the project. + +After that, copy the `docker-compose.override.example.yml` to `docker-compose.override.yml` and set the environment variables: + +```yaml +services: + anon3anon: + environment: + TELEGRAM_BOT_TOKEN: 123:ABC # The token for your bot, obtained from t.me/BotFather + OWNER_CHAT_ID: 123 # ID of your chat with your bot +``` + +And you're set! Lastly, run the app: + +```shell +./bin/a3acompose up -d +``` + +While making changes to the app, don't forget to restart the container: + +```shell +docker restart anon3anon +``` + +When you're finished working on the project, bring it down using this command: + +```shell +./bin/a3acompose down +``` diff --git a/bin/.gitignore b/bin/.gitignore index 7f08c9d..4e53720 100644 --- a/bin/.gitignore +++ b/bin/.gitignore @@ -1 +1,2 @@ -anon3anon +/anon3anon +/brewkit diff --git a/bin/a3abrewkit b/bin/a3abrewkit new file mode 100755 index 0000000..5d86fa6 --- /dev/null +++ b/bin/a3abrewkit @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +set -o errexit + +WORK_DIR=$(dirname "$(dirname "$(readlink -f "$0")")") + +BREWKIT_VERSION="v1.0.0" +BREWKIT_URL="https://github.com/ispringtech/brewkit/releases/download/$BREWKIT_VERSION/brewkit_amd64" +BREWKIT_BINARY="bin/brewkit" + +pushd "$WORK_DIR" >/dev/null + +if [[ ! -f "$BREWKIT_BINARY" ]]; then + echo "installing brewkit..." + wget -q -O "$BREWKIT_BINARY" "$BREWKIT_URL" + chmod +x "$BREWKIT_BINARY" +fi + +"$WORK_DIR/$BREWKIT_BINARY" "$@" + +popd >/dev/null diff --git a/bin/a3acompose b/bin/a3acompose new file mode 100755 index 0000000..3e251ad --- /dev/null +++ b/bin/a3acompose @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +set -o errexit + +WORK_DIR=$(dirname "$(dirname "$(readlink -f "$0")")") +PROJECT_NAME=$(basename "$WORK_DIR") + +pushd "$WORK_DIR" >/dev/null + +docker-compose -p "$PROJECT_NAME" "$@" + +popd >/dev/null diff --git a/brewkit.jsonnet b/brewkit.jsonnet new file mode 100644 index 0000000..c99ded5 --- /dev/null +++ b/brewkit.jsonnet @@ -0,0 +1,7 @@ +local project = import 'brewkit/project.libsonnet'; + +local appIDs = [ + "anon3anon", +]; + +project.project(appIDs) diff --git a/brewkit/images.libsonnet b/brewkit/images.libsonnet new file mode 100644 index 0000000..7f0733b --- /dev/null +++ b/brewkit/images.libsonnet @@ -0,0 +1,3 @@ +{ + gobuilder: "golang:1.22.5" +} diff --git a/brewkit/project.libsonnet b/brewkit/project.libsonnet new file mode 100644 index 0000000..92296b4 --- /dev/null +++ b/brewkit/project.libsonnet @@ -0,0 +1,83 @@ +local images = import 'images.libsonnet'; + +local cache = std.native('cache'); +local copy = std.native('copy'); +local copyFrom = std.native('copyFrom'); + +local gosources = [ + "go.mod", + "go.sum", + "cmd", + "pkg", +]; + +local gocache = [ + cache("go-build", "/app/cache"), + cache("go-mod", "/go/pkg/mod"), +]; + +{ + project(appIDs):: { + apiVersion: "brewkit/v1", + + targets: { + all: ["modules", "build"], + } + { + modules: ["gotidy", "modulesvendor"], + + gotidy: { + from: "gobase", + workdir: "/app", + cache: gocache, + ssh: {}, + command: "go mod tidy", + output: { + artifact: "/app/go.*", + "local": ".", + }, + }, + + modulesvendor: { + from: "gotidy", + workdir: "/app", + cache: gocache, + command: "go mod vendor", + output: { + artifact: "/app/vendor", + "local": "vendor", + }, + }, + + build: [appID for appID in appIDs], + } + { + [appID]: { + from: "gobase", + workdir: "/app", + cache: gocache, + dependsOn: ["modules"], + command: "go build -trimpath -v -o ./bin/" + appID + " ./cmd/" + appID, + output: { + artifact: "/app/bin/" + appID, + "local": "./bin" + } + } + for appID in appIDs + } + { + gobase: { + from: images.gobuilder, + workdir: "/app", + env: { + GOCACHE: "/app/cache/go-build", + CGO_ENABLED: "0" + }, + copy: copyFrom('gosources', '/app', '/app') + }, + + gosources: { + from: "scratch", + workdir: "/app", + copy: [copy(source, source) for source in gosources] + }, + } + } +} diff --git a/docker-compose.override.example.yml b/docker-compose.override.example.yml new file mode 100644 index 0000000..f4660db --- /dev/null +++ b/docker-compose.override.example.yml @@ -0,0 +1,5 @@ +services: + anon3anon: + environment: + TELEGRAM_BOT_TOKEN: 123:ABC + OWNER_CHAT_ID: 123 diff --git a/docker-compose.yml b/docker-compose.yml index 71256f4..cfdb521 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,4 +6,3 @@ services: dockerfile: docker/Dockerfile-local volumes: - "./bin:/app/bin" - env_file: .env