Skip to content

Commit

Permalink
Merge pull request #26 from PlaceOS/service-version
Browse files Browse the repository at this point in the history
feat: conform to PlaceOS::Model::Version
  • Loading branch information
tassja authored Jun 25, 2021
2 parents d0d3ec0 + 955df12 commit db2b2c1
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 21 deletions.
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM crystallang/crystal:1.0.0-alpine as builder
ARG PLACE_COMMIT="DEV"
ARG PLACE_VERSION="DEV"

WORKDIR /build

Expand All @@ -10,7 +12,9 @@ RUN CRFLAGS="--static" shards install --production --ignore-crystal-version

COPY src /build/src

RUN crystal build --error-trace --static --release --no-debug -o bin/frontends src/app.cr
RUN PLACE_COMMIT=$PLACE_COMMIT \
PLACE_VERSION=$PLACE_VERSION \
crystal build --release --no-debug --error-trace -o bin/frontends src/app.cr

FROM alpine:3.11
WORKDIR /app
Expand Down
22 changes: 9 additions & 13 deletions shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ shards:

action-controller:
git: https://github.com/spider-gazelle/action-controller.git
version: 4.4.1
version: 4.5.0

active-model:
git: https://github.com/spider-gazelle/active-model.git
Expand All @@ -21,13 +21,9 @@ shards:
git: https://github.com/spider-gazelle/bindata.git
version: 1.9.0

bisect:
git: https://github.com/spider-gazelle/bisect.git
version: 1.2.1

connect-proxy:
git: https://github.com/spider-gazelle/connect-proxy.git
version: 1.2.1
version: 1.4.0

crc16:
git: https://github.com/maiha/crc16.cr.git
Expand All @@ -45,6 +41,10 @@ shards:
git: https://github.com/sija/debug.cr.git
version: 2.0.1

dtls:
git: https://github.com/spider-gazelle/crystal-dtls.git
version: 0.9.0

etcd:
git: https://github.com/place-labs/crystal-etcd.git
version: 1.2.4
Expand Down Expand Up @@ -111,15 +111,15 @@ shards:

placeos-driver:
git: https://github.com/placeos/driver.git
version: 5.1.1
version: 5.3.13

placeos-log-backend:
git: https://github.com/place-labs/log-backend.git
version: 0.4.0

placeos-models:
git: https://github.com/placeos/models.git
version: 4.18.2
version: 5.5.0

placeos-resource:
git: https://github.com/place-labs/resource.git
Expand All @@ -129,10 +129,6 @@ shards:
git: https://github.com/ysbaddaden/pool.git
version: 0.2.4

priority-queue:
git: https://github.com/spider-gazelle/priority-queue.git
version: 1.0.1

promise:
git: https://github.com/spider-gazelle/promise.git
version: 2.2.2
Expand Down Expand Up @@ -179,7 +175,7 @@ shards:

tasker:
git: https://github.com/spider-gazelle/tasker.git
version: 2.0.3
version: 2.0.5

tokenizer:
git: https://github.com/spider-gazelle/tokenizer.git
Expand Down
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies:

placeos-models:
github: placeos/models
version: ~> 4.13
version: ~> 5.3

placeos-log-backend:
github: place-labs/log-backend
Expand Down
3 changes: 2 additions & 1 deletion spec/helper.cr
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
require "file_utils"
require "placeos-log-backend"
require "placeos-models/spec/generator"

require "../src/placeos-frontends"
require "../lib/action-controller/spec/curl_context"
require "action-controller/server"

require "spec"

Expand Down
18 changes: 18 additions & 0 deletions spec/root_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require "./helper"

module PlaceOS::Frontends::Api
describe Root do
with_server do
it "health checks" do
result = curl("GET", "/api/frontends/v1/")
result.success?.should be_true
end

it "should check version" do
result = curl("GET", "/api/frontends/v1/version")
result.status_code.should eq 200
PlaceOS::Model::Version.from_json(result.body).service.should eq "frontends"
end
end
end
end
6 changes: 4 additions & 2 deletions src/constants.cr
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
require "secrets-env"

module PlaceOS::Frontends
APP_NAME = "frontends"
VERSION = {{ `shards version "#{__DIR__}"`.chomp.stringify.downcase }}
APP_NAME = "frontends"
VERSION = {{ `shards version "#{__DIR__}"`.chomp.stringify.downcase }}
BUILD_TIME = {{ system("date -u").stringify }}
BUILD_COMMIT = {{ env("PLACE_COMMIT") || "DEV" }}

PROD = (ENV["SG_ENV"]? || ENV["ENV"]?) == "production"

Expand Down
4 changes: 4 additions & 0 deletions src/placeos-frontends/client.cr
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ module PlaceOS::Frontends
Array(String).from_json(response.body)
end

def version : PlaceOS::Model::Version
Model::Version.from_json(get("/version").body)
end

###########################################################################

def initialize(
Expand Down
11 changes: 8 additions & 3 deletions src/placeos-frontends/controllers/root.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require "./base"

require "placeos-models/version"

module PlaceOS::Frontends::Api
class Root < Base
base "/api/frontends/v1"
Expand All @@ -9,9 +11,12 @@ module PlaceOS::Frontends::Api
end

get "/version", :version do
render :ok, json: {
version: VERSION.to_s,
}
render :ok, json: PlaceOS::Model::Version.new(
version: VERSION,
build_time: BUILD_TIME,
commit: BUILD_COMMIT,
service: APP_NAME
)
end
end
end

0 comments on commit db2b2c1

Please sign in to comment.