CLI licenses action #39
|
@ -6,9 +6,10 @@ RUN shards install --production
|
|||
|
||||
FROM crystallang/crystal:1.3-alpine as builder
|
||||
ARG BUILD_ENV
|
||||
WORKDIR /app
|
||||
WORKDIR /app/backend
|
||||
COPY --from=deps /app/shard.yml /app/shard.lock ./
|
||||
COPY --from=deps /app/lib ./lib
|
||||
COPY ./LICENSE ./LICENSE
|
||||
COPY ./src ./src
|
||||
RUN if [ "${BUILD_ENV}" = "development" ]; then \
|
||||
time shards build -Ddevelopment --static --verbose -s -p -t; \
|
||||
|
@ -19,7 +20,7 @@ RUN if [ "${BUILD_ENV}" = "development" ]; then \
|
|||
FROM alpine as runner
|
||||
WORKDIR /app
|
||||
RUN adduser -S backend -u 1001
|
||||
COPY --from=builder /app/bin ./bin
|
||||
COPY --from=builder /app/backend/bin ./bin
|
||||
COPY ./db ./db
|
||||
USER backend
|
||||
EXPOSE 80
|
||||
|
|
21
docker/backend/LICENSE
Normal file
21
docker/backend/LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2022 Dominic Grimm
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -8,6 +8,10 @@ shards:
|
|||
git: https://github.com/mrrooijen/commander.git
|
||||
version: 0.4.0
|
||||
|
||||
compiled_license:
|
||||
git: https://git.dergrimm.net/dergrimm/compiled_license.git
|
||||
version: 2.0.0
|
||||
|
||||
db:
|
||||
git: https://github.com/crystal-lang/crystal-db.git
|
||||
version: 0.10.1
|
||||
|
|
|
@ -50,3 +50,5 @@ dependencies:
|
|||
github: spider-gazelle/crystal-ldap
|
||||
ldap_escape:
|
||||
git: https://git.dergrimm.net/dergrimm/ldap_escape.git
|
||||
compiled_license:
|
||||
git: https://git.dergrimm.net/dergrimm/compiled_license.git
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
require "commander"
|
||||
|
||||
require "./db"
|
||||
|
||||
module Backend
|
||||
module CLI
|
||||
extend self
|
||||
|
||||
def run : Nil
|
||||
cli = Commander::Command.new do |cmd|
|
||||
cmd.use = "backend"
|
||||
cmd.long = "Mentorenwahl backend CLI"
|
||||
|
||||
cmd.run do
|
||||
puts cmd.help
|
||||
end
|
||||
|
||||
cmd.commands.add do |c|
|
||||
c.use = "version"
|
||||
c.long = "Print version"
|
||||
|
||||
c.run do
|
||||
puts Backend::VERSION
|
||||
end
|
||||
end
|
||||
|
||||
cmd.commands.add do |c|
|
||||
c.use = "run"
|
||||
c.long = "Run the backend"
|
||||
|
||||
c.run do
|
||||
Backend.run
|
||||
end
|
||||
end
|
||||
|
||||
cmd.commands.add do |c|
|
||||
c.use = "register <username> <role>"
|
||||
c.long = "Seeds the database with required data"
|
||||
|
||||
c.flags.add do |f|
|
||||
f.name = "admin"
|
||||
f.long = "--admin"
|
||||
f.default = false
|
||||
f.description = "Register as admin"
|
||||
end
|
||||
|
||||
c.run do |opts, args|
|
||||
username = args[0]
|
||||
role = Db::UserRole.parse(args[1].downcase)
|
||||
print "Register '#{username}' as '#{role}'#{opts.bool["admin"] ? " with admin privileges" : nil}? [y/N] "
|
||||
abort unless (gets(chomp: true) || "").strip.downcase == "y"
|
||||
|
||||
user = Db::User.create!(username: username, role: role.to_s, admin: opts.bool["admin"])
|
||||
|
||||
puts "Done!"
|
||||
|
||||
puts "---"
|
||||
puts "User: #{user.id}"
|
||||
puts "Role: #{user.role}"
|
||||
puts "Admin: #{user.admin}"
|
||||
puts "---"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Commander.run(cli, ARGV)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,3 +1,74 @@
|
|||
require "commander"
|
||||
require "compiled_license"
|
||||
require "../backend"
|
||||
|
||||
Backend::CLI.run
|
||||
cli = Commander::Command.new do |cmd|
|
||||
cmd.use = "backend"
|
||||
cmd.short = "Mentorenwahl backend CLI"
|
||||
|
||||
cmd.run do
|
||||
puts cmd.help
|
||||
end
|
||||
|
||||
cmd.commands.add do |c|
|
||||
c.use = "version"
|
||||
c.short = "Prints version"
|
||||
c.long = c.short
|
||||
|
||||
c.run do
|
||||
puts Backend::VERSION
|
||||
end
|
||||
end
|
||||
|
||||
cmd.commands.add do |c|
|
||||
c.use = "licenses"
|
||||
c.short = "Prints licenses of projects used"
|
||||
c.long = c.short
|
||||
|
||||
c.run do
|
||||
puts CompiledLicense::LICENSES
|
||||
end
|
||||
end
|
||||
|
||||
cmd.commands.add do |c|
|
||||
c.use = "run"
|
||||
c.short = "Run the backend"
|
||||
c.long = c.short
|
||||
|
||||
c.run do
|
||||
Backend.run
|
||||
end
|
||||
end
|
||||
|
||||
cmd.commands.add do |c|
|
||||
c.use = "register <username> <role>"
|
||||
c.short = "Seeds the database with required data"
|
||||
c.long = c.short
|
||||
|
||||
c.flags.add do |f|
|
||||
f.name = "admin"
|
||||
f.long = "--admin"
|
||||
f.default = false
|
||||
f.description = "Register as admin"
|
||||
end
|
||||
|
||||
c.run do |opts, args|
|
||||
username = args[0]
|
||||
role = Backend::Db::UserRole.parse(args[1].downcase)
|
||||
print "Register '#{username}' as '#{role}'#{opts.bool["admin"] ? " with admin privileges" : nil}? [y/N] "
|
||||
abort unless (gets(chomp: true) || "").strip.downcase == "y"
|
||||
|
||||
user = Backend::Db::User.create!(username: username, role: role.to_s, admin: opts.bool["admin"])
|
||||
|
||||
puts "Done!"
|
||||
|
||||
puts "---"
|
||||
puts "User: #{user.id}"
|
||||
puts "Role: #{user.role}"
|
||||
puts "Admin: #{user.admin}"
|
||||
puts "---"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Commander.run(cli, ARGV)
|
||||
|
|
Loading…
Reference in a new issue