Code Monkey home page Code Monkey logo

geekapk's Introduction

Spring GeekApk Server checks code size agpl-3.0

Cup - The Mascot for GeekApk
(illustration by duangsuse)

The way to get started is to quit talking and begin doing. — Walt Disney

Introduction

GeekApk Spring server built with (*v*) and Kotlin/SpringBoot by ♥\_(ㇱ)_/✐

Features in version 1.0♭

  • Migrations (Export data tables to binary file)
  • RPC interfaces (server, admin, category, user, app/collab, reversion, comment, star, follow, timeline, notification)
  • User last online, App pinned comment
  • GeekApk bot i18n
  • Minimal counter check before Data pull
  • MetaApp for users
  • AppType, GeekApk bot
  • Query Combating Language support (bulk query)
  • Lexical scoping (lambda calculus) for the QCL Interpreter
  • GeekPush Server-side-push support

Deploying

Java Runtime

GeekApk Spring is a simple application, or microservice (and transitively, JavaEE Platform Application) built against SpringBoot

A Java Runtime with sufficient dynamic linking requirements (like spring boot runtime dependencies) is required to run GeekApk

This project's Kotlin compiler is configured to generate code for JVM 1.8, which is popular in nowadays Java server-side development

Requirements: JRE 1.8 or above

Recommended: Oracle JDK/JRE or OpenJDK 8-11

GraalVM with Ahead-Of-Time optimizations is also a good option for the server program runtime (since SpringBoot has been migrated to SubstrateVM)

Required configuration properties

Since GeekApk is a RDBMS-based web backend application, a working PostgreSQL DBMS instance is required to run GeekApk

Setup the GeekApk database with following commands

psql -c 'CREATE DATABASE geekapk_db;' -U postgres # Create database in pg clusters for geekapk with user postgres
sudo -u postgres psql

(and execute SQL statements)

CREATE USER geekapk WITH PASSWORD 'password'; -- Create geekapk application database user

GRANT ALL PRIVILEGES ON DATABASE geekapk_db TO geekapk; -- Make this database geekapk owned

To make a usable database for GeekApk

For database connection and authentication, you may need to change the cluster's pg_hba.conf, please make sure that PostgreSQL is only accepting connections from local loopback for server security.

All microservice properties are in ./application.properties nested in application classpath

Make GeekApk a service (continuous running)

We suppose that you choose to deploy geekapk service to your own Linux machine, in most cases this means you will deploy your service onto your VPS

Amazon Lambda / OpenShift and others is not talked here.

Systemd is a popular daemon service manager in modern GNU/Linux distributions, and it's recommended to use when making microservices continuous running

create a file with these content in /lib/systemd/system/geekapk_spring.service:

[Unit]
Description=GeekApk Spring server
After=network.target
Requires=postgresql.service

[Service]
Type=simple

# Recommended to run as 
User=geekapk
Group=geekapk
WorkingDirectory=/home/geekapk/service

LimitNOFILE=10
ExecStart=#Your server start command

Restart=always
RestartSec=2

Environment=Key=Value K=V

CapabilityBoundingSet=CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_BIND_SERVICE

#ExecStartPre=-/bin/setcap 'cap_net_bind_service=+eip' your_server_jvm_binary
#PermissionsStartOnly=true # Only ExecStartPre to be run as root (but not ExecStart)

[Install]
WantedBy=multi-user.target

(see systemd service file format manual by man systemd.service, you can edit config file using nano, vi and vim)

Then you can use sudo systemctl start geekapk_spring to start the server

For server status checking, execute shell command sudo systemctl status geekapk_spring.service

And when you're sure about your configuration, run sudo systemctl enable geekapk_spring to auto-start the service when system boots

Process control daemon Supervisor is also a good option for this case

man page for systemd | related practice | related document

(Optional) Make a reverse proxy

CloudFlare is also a usable option for reverse proxying the service

Nginx configuration

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
    worker_connections 65535;
    multi_accept on;
}

http {
    include mime.types;
    upstream geeksvc {
        server localhost:233;
    }

    server {
        listen 80;
        server_name api.geekapk.org;

        location / {
            proxy_pass http://geeksvc;
            proxy_redirect off;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }
}

Apache configuration

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

<VirtualHost *:443>
    ServerName api.geekapk.org
    ProxyPass / http://localhost:233/
    ProxyPassReverse / http://localhost:233/
</VirtualHost>

Server stress testing

You can use wrk / siege / ab for server stress testing

You SHOULD NOT stress testing on the production environment GeekApk API service, run stress tests on private machines.

# Using Apache HTTP server benchmarking tool
ab -n request_num -t timeout -c concurrency -m http_method -C cookie http://127.0.0.1:8080/

# Using Siege, a HTTP/FTP load tester and benchmarking utility
# -b means "no delays between requests"
siege -b -n request_num -t timeout -c concurrency -H "Cookie: ${cookies}" http://127.0.0.1:8080/

# use man ab / siege for documents

# Wrk is not packaged for most distributions, through.
# You can install it from scratch with the documentation from https://github.com/wg/wrk/wiki/Installing-Wrk-on-Linux

Configuration

All GeekApk application related properties (e.g. server access password) is in info.ini (default settings) and can be overridden in geekapk.ini, message translations (string templates) can be found in translations.ini

Add your configuration override file paths separated by column : in environment variable GEEKAPK_INI

Those configuration files are self-documented, just read inline comments and set the values on your purpose

API Mapping

Main

Others

The GeekApk API Server has built-in API documents, see API Index

References

Future reading

License

Copyright (C) 2019  duangsuse

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.

geekapk's People

Contributors

duangsuse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

illuz placya

geekapk's Issues

Looking for contributors

https://t.me/dsuse/9048

内个,有没有大佬想加入 duangsuse/GeekApk 开发的呢? 🤐
我明天要回老家玩几天,可能不能写代码了

现在 GeekApk 还差点自动化测试和控制器逻辑,其他的应该都是可以用的了

期望是继续进行测试驱动开发,不知道有没有愿意贡献的大佬(

项目的结构目前就是 Kotlin + SpringBoot,比较单纯的 MVC(现在没有 V,就是数据持久化层和控制器逻辑层

基本可以说修改一下 entity 包里面的 Entity 们和 controller 包里面的控制器逻辑就可以了,所有 server endpoints 接口上都绑定好了,差个业务逻辑

所有 HTTP API 文档在这里,当然 ApiDoc 类里面也有一些,冲突以这里的为标准

这里也个文档,大概是上面那个的注释
这里是最大的一个文档

如果发现设计有冲突的,就跳过,去实现没有问题的逻辑喵(

真正的开源精神:卧槽这项目有个地方错误处理没写好,我看看代码…嗯,就是个智障问题,顺手PR一波…

诶,作者回复了,原来这地方还能这么写…学到了…

卧槽这项目怎么连Xxx都不支持…我看看咋整…嗯,做出来了,顺手PR一下…

duangsuse: 这才是真正的开源精神啊!(求滋滋

[KtLime] Use lexical scoping or stableized dynamic scoping

replace macro-filling "expander" in KtLime

  • binding variable id shadow
(((# (a)
    (# (a) a)) 1) 2)

; expected: 2
; actual: 1
  • use lexical scoping
(-> a 199)

(-> get-a (# () a))

(println a) ; 199

(-> print-a (# (a)
  (println (get-a))))

(print-a 233) ; 233

[GA v1♭] [NOTES] TODO() by duangsuse

TODO

https://github.com/bjzhou/Coolapk-kotlin

  • TravisCI integration support
  • AppType
  • Add getXXXXCount() Interfaces for client update event check
  • QCL interpreter (v1.1b)
  • Add platform task for GeekApk pictures(copycat 🐱
  • GeekApk i18n
  • User last-online-at time
  • App pinned comment
  • Test driven development
  • Add GET Views for non-GET APIs (debug view) (v1.1b)
  • Add PATCH (Bulk update entity properties) APIs (v1.1b)

TODO later

  • Topics like CoolApk(yes, with 'subscribe' feature) (merging extra timeline)
  • MessageHeader specification (At mentation user, join topics...)
  • Make a built-in GeekWidget plugin replacing coolapk's App discovery
  • GeekPush & support user (cross device) push events (server-side interface for cloudInstall)
  • Database migrate program
  • Support J2EE servlet containers arithetcute (v2)

"NOT" TODO

  • App discovery like CoolApk

WHY: GeekApk Users can create apps on their purpose, and GeekApk have a GeekWidget plugin replacing coolapk's App discovery (inline picture in comments)

  • favorite comments(o:feeds) (designment reasons)
  • (un)recommend(+1) comments (designment reasons)
  • Headline like CoolApk (Badges in GeekApk actually the same)
  • App QR Code
  • Recommended Apps and Albums (AppDeps in GeekApk will "implement" that)
  • Avatar/Other Image storage (Use external services like sm.ms instead)
  • PM like CoolApk (GeekStream in v2 provides "PM" feature)
  • download stat (but, GeekApk Hits is almost the same...)
  • rating for apps (star is enough)
  • "Feed"s (GeekApk uses MetaApp to combine a "Feed Area" with its users)
  • pictures (Already has one)
  • App gift codes
  • block users on the server side
  • App tags (GeekDeps...)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.