Skip to content

Commit

Permalink
fsnotes is working
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksei M committed Jan 17, 2024
1 parent 758d976 commit 87f385d
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 56 deletions.
99 changes: 99 additions & 0 deletions .github/workflows/docker-publish-fsnotes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Docker

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

on:
# schedule:
# - cron: '21 22 * * *'
push:
# branches: [ "main" ]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
pull_request:
branches: [ "main" ]

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}-fsnotes


jobs:
build:

runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@6e04d228eb30da1757ee4e1dd75a0ec73a653e06 #v3.1.1
with:
cosign-release: 'v2.1.1'

# Set up BuildKit Docker container builder to be able to build
# multi-platform images and export cache
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: .
file: ./fsnotes/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

# Sign the resulting Docker image digest except on PRs.
# This will only write to the public Rekor transparency log when the Docker
# repository is public to avoid leaking data. If you would like to publish
# transparency data even for private images, pass --force to cosign below.
# https://github.com/sigstore/cosign
- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
TAGS: ${{ steps.meta.outputs.tags }}
DIGEST: ${{ steps.build-and-push.outputs.digest }}
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
55 changes: 35 additions & 20 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ services:
- 51413:51413/udp
restart: unless-stopped
tbot:
# image: ghcr.io/ishua/a3bot5-tbot:latest
image: tbot
build:
context: ./
dockerfile: ./tbot/Dockerfile
image: ghcr.io/ishua/a3bot5-tbot:latest
# image: tbot
# build:
# context: ./
# dockerfile: ./tbot/Dockerfile
restart: unless-stopped
depends_on:
- redis
Expand All @@ -51,11 +51,11 @@ services:
volumes:
- ./tbot/conf/:/conf
restjobs:
# image: ghcr.io/ishua/a3bot5-restjobs:latest
image: restjobs
build:
context: ./
dockerfile: ./restjobs/Dockerfile
image: ghcr.io/ishua/a3bot5-restjobs:latest
# image: restjobs
# build:
# context: ./
# dockerfile: ./restjobs/Dockerfile
restart: unless-stopped
depends_on:
- redis
Expand All @@ -64,11 +64,11 @@ services:
volumes:
- ./restjobs/conf/:/conf
ytd2feed:
# image: ghcr.io/ishua/a3bot5-ytd2feed:latest
image: ytd2feed
build:
context: ./
dockerfile: ./ytd2feed/Dockerfile
image: ghcr.io/ishua/a3bot5-ytd2feed:latest
# image: ytd2feed
# build:
# context: ./
# dockerfile: ./ytd2feed/Dockerfile
restart: unless-stopped
depends_on:
- redis
Expand All @@ -78,11 +78,11 @@ services:
- ./ytd2feed/conf/:/srv/conf
- ./ytd2feed/data/:/srv/data
transmission_bot:
# image: ghcr.io/ishua/a3bot5-ytd2feed:latest
image: transmission_bot
build:
context: ./
dockerfile: ./transmission/Dockerfile
image: ghcr.io/ishua/a3bot5-transmission:latest
# image: transmission_bot
# build:
# context: ./
# dockerfile: ./transmission/Dockerfile
restart: unless-stopped
depends_on:
- redis
Expand All @@ -91,3 +91,18 @@ services:
- dnet
volumes:
- ./transmission/conf/:/srv/conf
fsnotes:
image: ghcr.io/ishua/a3bot5-fsnotes:latest
# image: fsnotes
# build:
# context: /Users/amamyrin/Documents/repo/a3bot5/
# dockerfile: ./fsnotes/Dockerfile
restart: unless-stopped
depends_on:
- redis
- tbot
networks:
- dnet
volumes:
- ./fsnotes/conf/:/conf
- ./fsnotes/temp/data/:/data
3 changes: 2 additions & 1 deletion fsnotes/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ RUN apk add -U tzdata
COPY --from=build /etc/ssl/certs/ca-certificates.crt \
/etc/ssl/certs/ca-certificates.crt
COPY --from=build /build/app /app
RUN mkdir /configs
RUN mkdir /conf
RUN mkdir /data

ENTRYPOINT ["/app"]
55 changes: 30 additions & 25 deletions fsnotes/cmd/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"log"

"github.com/cristalhq/aconfig"
"github.com/cristalhq/aconfig/aconfigyaml"
Expand All @@ -14,7 +15,8 @@ import (
type MyConfig struct {
Redis string `default:"redis:6379" env:"REDIS" usage:"connect str to redis"`
SubChannel string `default:"fsnotes" usage:"channel for subscribe jobs"`
RepoPath string `default:"data/fsnotes" usage:" path to repository fsnotest"`
TbotChannel string `default:"tbot" usage:"channel for jobs for tbot"`
RepoPath string `default:"data/fsnotes" usage:" path to repository fsnotes"`
RepoUrl string `required:"true"`
RepoAccessToken string `env:"REPOACCESSTOKEN" required:"true"`
RepoDiaryPath string `required:"true"`
Expand Down Expand Up @@ -45,20 +47,20 @@ func init() {
}

// // init redis
// func init() {
// rdb = &Pubsub{redis.NewClient(&redis.Options{
// Addr: cfg.Redis,
// Password: "", // no password set
// DB: 0, // use default DB
// })}
// log.Println("Redis: " + cfg.Redis)
// }
// func (r Pubsub) Pub(ctx context.Context, value string) {
// err := r.Publish(ctx, cfg.TbotChannel, value).Err()
// if err != nil {
// log.Println("publish error: " + err.Error())
// }
// }
func init() {
rdb = &Pubsub{redis.NewClient(&redis.Options{
Addr: cfg.Redis,
Password: "", // no password set
DB: 0, // use default DB
})}
log.Println("Redis: " + cfg.Redis)
}
func (r Pubsub) Pub(ctx context.Context, value string) {
err := r.Publish(ctx, cfg.TbotChannel, value).Err()
if err != nil {
log.Println("publish error: " + err.Error())
}
}

// init git
func init() {
Expand All @@ -74,15 +76,18 @@ func main() {
ctx := context.Background()
myRepo = repo.NewGitFile(cfg.RepoPath, cfg.RepoDiaryPath, myGit)
d := domain.NewDiary(myRepo)
m := domain.NewModel(d, Test{})
m.DoJob(ctx, `
{
"text":"/note diary add entry 2"
}
`)
}
m := domain.NewModel(d, rdb)

type Test struct {
}
pubsub := rdb.Subscribe(ctx, cfg.SubChannel)

log.Println("Subscribe to channel: " + cfg.SubChannel)
// Close the subscription when we are done.
defer pubsub.Close()

func (r Test) Pub(ctx context.Context, value string) {}
ch := pubsub.Channel()

for msg := range ch {
log.Println(msg.Payload)
go m.DoJob(ctx, msg.Payload)
}
}
7 changes: 3 additions & 4 deletions fsnotes/conf/fsnote_config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# redis: localhost:6379
sub_channel: fsnote
repo_path: "temp/fsnotes"
repo_url: ""
repo_access_token: ""
repo_url: "some github https repo"
repo_access_token: "github token"
repo_diary_path: "some file"
8 changes: 4 additions & 4 deletions fsnotes/internal/domain/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ type Msg struct {
}

const helpText = `This is help for /note command
- /note diary add 5bx <text>
- /note diary add entry <text>
- /note diary add 5bx -text-
- /note diary add entry -text-
- /note diary help
- /note quick <text>
- /note quick -text-
- synonyms: diary = d, add=a, entry=e, 5bx=5, quick=q`

type Note struct {
Expand Down Expand Up @@ -109,7 +109,7 @@ func (m *Msg) ParseCommand() (Note, error) {
// note diary list week/month/day
// note help
texts := strings.Split(m.Text, " ")
if len(texts) <= 2 {
if len(texts) < 2 {
return Note{}, fmt.Errorf("Wrong fsnotes command")
}
if texts[1] == "help" {
Expand Down
2 changes: 1 addition & 1 deletion restjobs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ RUN apk add -U tzdata
COPY --from=build /etc/ssl/certs/ca-certificates.crt \
/etc/ssl/certs/ca-certificates.crt
COPY --from=build /build/app /app
RUN mkdir /configs
RUN mkdir /conf

ENTRYPOINT ["/app"]
2 changes: 1 addition & 1 deletion tbot/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ RUN apk add -U tzdata
COPY --from=build /etc/ssl/certs/ca-certificates.crt \
/etc/ssl/certs/ca-certificates.crt
COPY --from=build /build/app /app
RUN mkdir /configs
RUN mkdir /conf

ENTRYPOINT ["/app"]

0 comments on commit 87f385d

Please sign in to comment.