git.iko.soy/typeable/octopod
on master help sign in
Reflex setup (#24)
commit22c695271ee50e215a612e4fa5d2f9217a22841a authorNikita <anisimoff.nikita@gmail.com> dateMon 15 Jun 2020, 14:12 (6 years ago) parent6551113
37 files changed+468−241
.gitignore+1 Makefile+14−11 README.md+24 cabal.project+4 default.nix+29−42 dm-backend/LICENSE+30 dm-backend/Setup.hs+2 dm-backend/app/dmc/Main.hs+6 dm-backend/app/dms/Main.hs+6 dm.cabal → dm-backend/dm-backend.cabal+7−13 src/API/Types/Deployment.hs → dm-backend/src/API/Types/Deployment.hs src/API/Types/DeploymentInfo.hs → dm-backend/src/API/Types/DeploymentInfo.hs src/DMC.hs → dm-backend/src/DMC.hs+1−1 src/DMC/Args.hs → dm-backend/src/DMC/Args.hs src/DMS.hs → dm-backend/src/DMS.hs+2−1 src/DMS/Args.hs → dm-backend/src/DMS/Args.hs src/DMS/Lib.hs → dm-backend/src/DMS/Lib.hs dm-backend/src/Orphans.hs+16 src/TLS.hs → dm-backend/src/TLS.hs dm-backend/src/Types.hs+79 dm-backend/test/Spec.hs+2 dm-common/CHANGELOG.md+5 dm-common/LICENSE+30 dm-common/Setup.hs+2 dm-common/dm-common.cabal+45 dm-common/src/Common.hs+2 src/API.hs → dm-common/src/Common/API.hs+2−2 dm-common/src/Common/Types.hs+80 dm-frontend/CHANGELOG.md+5 dm-frontend/LICENSE+30 dm-frontend/Setup.hs+2 dm-frontend/dm-frontend.cabal+26 dm-frontend/src/Main.hs+8 nix/default.nix+8−16 release.sh−2 shell.nix−13 src/Types.hs−140
.gitignore+1
@@ -4,3 +4,4 @@ default.nix
44result
55dms-docker
66*~
7+dist-newstyle
Makefile+14−11
@@ -1,22 +1,25 @@
11.PHONY: build repl shell ghcid push-dms
22
3−build: update-default-nix
4− nix build nixpkgs.haskellPackages.dm -I nixpkgs=nix
3+build:
4+ nix-build . -A ghc.dm-backend
55
6−repl: update-default-nix
7− nix-shell --pure shell.nix --run "cabal repl lib:dm" -I nixpkgs=nix
8−
9−update-default-nix:
10− nix-shell --pure -p cabal2nix --run "cabal2nix ." -I nixpkgs=nix > default.nix
6+repl:
7+ nix-shell . -A shells.ghc --run "cabal repl lib:dm-backend"
118
129update-b2b-helm-nix:
1310 nix-shell -p vgo2nix --run 'cd b2b-helm/tool && vgo2nix && cd ../..'
1411
15−shell: update-default-nix
16− nix-shell -I nixpkgs=nix
12+shell:
13+ nix-shell . -A shells.ghc
14+
15+shell-ghcjs:
16+ nix-shell . -A shells.ghcjs
17+
18+ghcid:
19+ nix-shell . -A shells.ghc --run 'ghcid -c "cabal new-repl dm-backend"'
1720
18−ghcid: update-default-nix
19− nix-shell --run 'ghcid -c "cabal new-repl"' -I nixpkgs=nix
21+ghcid-frontend:
22+ nix-shell . -A shells.ghc --run 'ghcid -c "cabal new-repl dm-frontend"'
2023
2124push-dms: build-docker
2225 ./release.sh
README.md+24
@@ -141,3 +141,27 @@ To make sure the actual image is being used, remove the old docker image and pul
141141docker rmi 560065381221.dkr.ecr.us-east-1.amazonaws.com/dmc:latest
142142docker pull 560065381221.dkr.ecr.us-east-1.amazonaws.com/dmc:latest
143143```
144+
145+# Develop
146+
147+Cache set up:
148+```
149+binary-caches = https://cache.nixos.org https://nixcache.reflex-frp.org
150+binary-cache-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= ryantrinkle.com-1:JJiAKaRv9mWgpVAz8dwewnZe0AzzEAzPkagE9SP5NWI=
151+binary-caches-parallel-connections = 40
152+```
153+
154+Enter shell to work on the backend:
155+```
156+make shell
157+```
158+
159+Enter shell to work on the frontend (with GHC):
160+```
161+make shell
162+```
163+
164+Enter shell to work on the frontend (with GHCJS):
165+```
166+make shell-ghcjs
167+```
cabal.projectnew file+4
@@ -0,0 +1,4 @@
1+packages:
2+ dm-common/
3+ dm-backend/
4+ dm-frontend/
default.nix+29−42
@@ -1,43 +1,30 @@
1−{ mkDerivation, aeson, async, base, bytestring, chronos, connection
2−, data-default-class, deriving-aeson, directory, fast-logger
3−, filepath, generic-lens, http-api-data, http-client
4−, http-client-tls, lens, mtl, network-uri, optparse-generic
5−, postgresql-error-codes, postgresql-simple, resource-pool, servant
6−, servant-client, servant-client-core, servant-server, stdenv
7−, temporary, text, tls, transformers, typed-process, warp, warp-tls
8−, x509, x509-store, x509-validation
1+{ sources ? import ./nix/sources.nix
2+, reflex-platform ? ((import sources.nixpkgs {}).fetchFromGitHub {
3+ owner = "reflex-frp";
4+ repo = "reflex-platform";
5+ rev = "5429278830e1555a577f2550e045ce7f7164aa65";
6+ sha256 = "1lp86cgccmim573rarsjny5vh0ygkfp5afq7006li0k9w2sw2d4c";
7+ })
98}:
10−mkDerivation {
11− pname = "dm";
12− version = "0.1.0.0";
13− src = ./.;
14− isLibrary = true;
15− isExecutable = true;
16− libraryHaskellDepends = [
17− aeson async base bytestring chronos connection data-default-class
18− deriving-aeson directory fast-logger filepath generic-lens
19− http-api-data http-client http-client-tls lens mtl network-uri
20− optparse-generic postgresql-error-codes postgresql-simple
21− resource-pool servant servant-client servant-client-core
22− servant-server temporary text tls transformers typed-process warp
23− warp-tls x509 x509-store x509-validation
24− ];
25− executableHaskellDepends = [
26− aeson async base bytestring chronos connection data-default-class
27− directory fast-logger filepath http-client http-client-tls mtl
28− network-uri optparse-generic postgresql-error-codes
29− postgresql-simple resource-pool servant servant-client
30− servant-client-core servant-server temporary text tls transformers
31− typed-process warp warp-tls x509 x509-store x509-validation
32− ];
33− testHaskellDepends = [
34− aeson async base bytestring chronos connection data-default-class
35− directory fast-logger filepath http-client http-client-tls mtl
36− network-uri optparse-generic postgresql-error-codes
37− postgresql-simple resource-pool servant servant-client
38− servant-client-core servant-server temporary text tls transformers
39− typed-process warp warp-tls x509 x509-store x509-validation
40− ];
41− homepage = "https://github.com/https://github.com/Aviora/dm#readme";
42− license = stdenv.lib.licenses.bsd3;
43−}
9+(import reflex-platform {}).project ({ pkgs, ... }: {
10+ useWarp = true;
11+
12+ packages = {
13+ dm-common = ./dm-common;
14+ dm-frontend = ./dm-frontend;
15+ dm-backend = ./dm-backend;
16+ };
17+
18+ overrides = hself: hsuper: {
19+ deriving-aeson = hsuper.callCabal2nix "deriving-aeson" sources.deriving-aeson { };
20+ servant = pkgs.haskell.lib.overrideCabal hsuper.servant (old: {
21+ postInstall = "";
22+ });
23+ };
24+
25+ shells = {
26+ ghc = ["dm-common" "dm-backend" "dm-frontend"];
27+ ghcjs = ["dm-common" "dm-frontend"];
28+ };
29+})
30+
dm-backend/LICENSEnew file+30
@@ -0,0 +1,30 @@
1+Copyright Author name here (c) 2020
2+
3+All rights reserved.
4+
5+Redistribution and use in source and binary forms, with or without
6+modification, are permitted provided that the following conditions are met:
7+
8+ * Redistributions of source code must retain the above copyright
9+ notice, this list of conditions and the following disclaimer.
10+
11+ * Redistributions in binary form must reproduce the above
12+ copyright notice, this list of conditions and the following
13+ disclaimer in the documentation and/or other materials provided
14+ with the distribution.
15+
16+ * Neither the name of Author name here nor the names of other
17+ contributors may be used to endorse or promote products derived
18+ from this software without specific prior written permission.
19+
20+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dm-backend/Setup.hsnew file+2
@@ -0,0 +1,2 @@
1+import Distribution.Simple
2+main = defaultMain
dm-backend/app/dmc/Main.hsnew file+6
@@ -0,0 +1,6 @@
1+module Main where
2+
3+import DMC
4+
5+main :: IO ()
6+main = runDMC
dm-backend/app/dms/Main.hsnew file+6
@@ -0,0 +1,6 @@
1+module Main where
2+
3+import DMS
4+
5+main :: IO ()
6+main = runDMS
dm.cabal → dm-backend/dm-backend.cabalrenamed+7−13
@@ -1,5 +1,5 @@
11cabal-version: 2.4
2−name: dm
2+name: dm-backend
33version: 0.1.0.0
44description: Please see the README on GitHub at <https://github.com/githubuser/dm#readme>
55homepage: https://github.com/https://github.com/Aviora/dm#readme
@@ -33,18 +33,17 @@ library
3333 , LambdaCase
3434 , OverloadedStrings
3535 , ScopedTypeVariables
36+ , StandaloneDeriving
3637 , TypeApplications
3738 , TypeOperators
3839 exposed-modules:
39− API
4040 DMC
4141 DMC.Args
4242 DMS
4343 DMS.Args
44+ Orphans
4445 TLS
4546 Types
46− other-modules:
47− Paths_dm
4847 hs-source-dirs:
4948 src
5049 build-depends:
@@ -57,6 +56,7 @@ library
5756 , data-default-class
5857 , deriving-aeson
5958 , directory
59+ , dm-common
6060 , fast-logger
6161 , filepath
6262 , generic-lens
@@ -90,8 +90,6 @@ executable dmc-exe
9090 main-is: Main.hs
9191 ghc-options: -Wall
9292 -Werror
93− other-modules:
94− Paths_dm
9593 hs-source-dirs:
9694 app/dmc
9795 ghc-options: -threaded -rtsopts -with-rtsopts=-N
@@ -104,7 +102,7 @@ executable dmc-exe
104102 , connection
105103 , data-default-class
106104 , directory
107− , dm
105+ , dm-backend
108106 , fast-logger
109107 , filepath
110108 , http-client
@@ -135,8 +133,6 @@ executable dms-exe
135133 main-is: Main.hs
136134 ghc-options: -Wall
137135 -Werror
138− other-modules:
139− Paths_dm
140136 hs-source-dirs:
141137 app/dms
142138 ghc-options: -threaded -rtsopts -with-rtsopts=-N
@@ -149,7 +145,7 @@ executable dms-exe
149145 , connection
150146 , data-default-class
151147 , directory
152− , dm
148+ , dm-backend
153149 , fast-logger
154150 , http-client
155151 , http-client-tls
@@ -178,8 +174,6 @@ executable dms-exe
178174test-suite dm-test
179175 type: exitcode-stdio-1.0
180176 main-is: Spec.hs
181− other-modules:
182− Paths_dm
183177 hs-source-dirs:
184178 test
185179 ghc-options: -threaded -rtsopts -with-rtsopts=-N
@@ -192,7 +186,7 @@ test-suite dm-test
192186 , connection
193187 , data-default-class
194188 , directory
195− , dm
189+ , dm-backend
196190 , fast-logger
197191 , filepath
198192 , http-client
src/API/Types/Deployment.hs → dm-backend/src/API/Types/Deployment.hsrenamed

The content is the same.

src/API/Types/DeploymentInfo.hs → dm-backend/src/API/Types/DeploymentInfo.hsrenamed

The content is the same.

src/DMC.hs → dm-backend/src/DMC.hsrenamed+1−1
@@ -27,7 +27,7 @@ import System.IO
2727import System.IO.Temp
2828import System.Process.Typed
2929
30−import API
30+import Common.API
3131import DMC.Args
3232import TLS (makeClientManager)
3333import Types
src/DMC/Args.hs → dm-backend/src/DMC/Args.hsrenamed

The content is the same.

src/DMS.hs → dm-backend/src/DMS.hsrenamed+2−1
@@ -27,8 +27,9 @@ import System.Log.FastLogger
2727import System.Process.Typed
2828
2929
30−import API
30+import Common.API
3131import DMS.Args
32+import Orphans ()
3233import TLS (createTLSOpts)
3334import Types
3435
src/DMS/Args.hs → dm-backend/src/DMS/Args.hsrenamed

The content is the same.

src/DMS/Lib.hs → dm-backend/src/DMS/Lib.hsrenamed

The content is the same.

dm-backend/src/Orphans.hsnew file+16
@@ -0,0 +1,16 @@
1+{-# OPTIONS_GHC -fno-warn-orphans #-}
2+module Orphans where
3+
4+import Database.PostgreSQL.Simple.FromField (FromField)
5+import Database.PostgreSQL.Simple.ToField (ToField)
6+
7+import Common.Types
8+
9+deriving instance FromField Action
10+deriving instance ToField Action
11+
12+deriving instance FromField DeploymentTag
13+deriving instance ToField DeploymentTag
14+
15+deriving instance FromField DeploymentName
16+deriving instance ToField DeploymentName
src/TLS.hs → dm-backend/src/TLS.hsrenamed

The content is the same.

dm-backend/src/Types.hsnew file+79
@@ -0,0 +1,79 @@
1+module Types
2+ ( module Common.Types
3+ , concatPair
4+ , concatPairWithAppEnv
5+ , formatEnvPairs
6+ , parseEnvs
7+ , ServerPort(..)
8+ , DBPoolSize(..)
9+ , DBConnectionString(..)
10+ , TLSCertPath(..)
11+ , TLSKeyPath(..)
12+ , TLSStorePath(..)
13+ , ProjectName(..)
14+ , Domain(..)
15+ , Namespace(..)
16+ , Command(..)
17+ , ArchiveRetention(..)) where
18+
19+import Data.Bifunctor
20+import Data.ByteString (ByteString)
21+import Data.Text as T
22+import Data.Traversable
23+
24+import Common.Types
25+
26+-- | Format for command arguments
27+concatPair :: EnvPair -> Text
28+concatPair (k, v) = k <> "=" <> v
29+
30+-- | Format for b2b-helm-tool / helm
31+concatPairWithAppEnv :: EnvPair -> Text
32+concatPairWithAppEnv pair = "b2b-app.env." <> concatPair pair
33+
34+-- | Format for output
35+formatEnvPairs :: EnvPairs -> Text
36+formatEnvPairs = T.unlines . fmap concatPair
37+
38+parseEnvs :: [Text] -> IO [(Text, Text)]
39+parseEnvs texts =
40+ for texts $ \t ->
41+ case T.findIndex (== '=') t of
42+ Just i -> pure $ bimap strip (T.tail . strip) $ T.splitAt i t
43+ Nothing -> error $
44+ "Malformed environment key-value pair " <> T.unpack t <>
45+ ", should be similar to FOO=bar"
46+
47+newtype ServerPort = ServerPort { unServerPort :: Int }
48+ deriving (Show)
49+
50+newtype DBPoolSize = DBPoolSize { unDBPoolSize :: Int }
51+ deriving (Show)
52+
53+newtype DBConnectionString = DbConnectionString
54+ { unDBConnectionString :: ByteString }
55+ deriving (Show)
56+
57+newtype TLSCertPath = TLSCertPath { unTLSCertPath :: ByteString }
58+ deriving (Show)
59+
60+newtype TLSKeyPath = TLSKeyPath { unTLSKeyPath :: ByteString }
61+ deriving (Show)
62+
63+newtype TLSStorePath = TLSStore { unTLSStorePath :: ByteString }
64+ deriving (Show)
65+
66+newtype ProjectName = ProjectName { unProjectName :: Text }
67+ deriving (Show)
68+
69+newtype Domain = Domain { unDomain :: Text }
70+ deriving (Show)
71+
72+newtype Namespace = Namespace { unNamespace :: Text }
73+ deriving (Show)
74+
75+newtype ArchiveRetention = ArchiveRetention { unArchiveRetention :: Int }
76+ deriving (Show)
77+
78+newtype Command = Command { unCommand :: Text }
79+ deriving (Show)
dm-backend/test/Spec.hsnew file+2
@@ -0,0 +1,2 @@
1+main :: IO ()
2+main = putStrLn "Test suite not yet implemented"
dm-common/CHANGELOG.mdnew file+5
@@ -0,0 +1,5 @@
1+# Revision history for common
2+
3+## 0.1.0.0 -- YYYY-mm-dd
4+
5+* First version. Released on an unsuspecting world.
dm-common/LICENSEnew file+30
@@ -0,0 +1,30 @@
1+Copyright (c) 2020, Anisimov Nikita
2+
3+All rights reserved.
4+
5+Redistribution and use in source and binary forms, with or without
6+modification, are permitted provided that the following conditions are met:
7+
8+ * Redistributions of source code must retain the above copyright
9+ notice, this list of conditions and the following disclaimer.
10+
11+ * Redistributions in binary form must reproduce the above
12+ copyright notice, this list of conditions and the following
13+ disclaimer in the documentation and/or other materials provided
14+ with the distribution.
15+
16+ * Neither the name of Anisimov Nikita nor the names of other
17+ contributors may be used to endorse or promote products derived
18+ from this software without specific prior written permission.
19+
20+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dm-common/Setup.hsnew file+2
@@ -0,0 +1,2 @@
1+import Distribution.Simple
2+main = defaultMain
dm-common/dm-common.cabalnew file+45
@@ -0,0 +1,45 @@
1+-- Initial common.cabal generated by cabal init. For further
2+-- documentation, see http://haskell.org/cabal/users-guide/
3+
4+name: dm-common
5+version: 0.1.0.0
6+-- synopsis:
7+-- description:
8+license: BSD3
9+license-file: LICENSE
10+author: Anisimov Nikita
11+maintainer: anisimoff.nikita@gmail.com
12+-- copyright:
13+-- category:
14+build-type: Simple
15+extra-source-files: CHANGELOG.md
16+cabal-version: >=1.10
17+
18+library
19+ exposed-modules: Common
20+ , Common.API
21+ , Common.Types
22+ -- other-modules:
23+ -- other-extensions:
24+ default-extensions: BlockArguments
25+ , ConstraintKinds
26+ , DataKinds
27+ , DeriveFunctor
28+ , DeriveGeneric
29+ , DerivingVia
30+ , DuplicateRecordFields
31+ , FlexibleContexts
32+ , GeneralizedNewtypeDeriving
33+ , LambdaCase
34+ , OverloadedStrings
35+ , ScopedTypeVariables
36+ , TypeApplications
37+ , TypeOperators
38+ build-depends: base >=4.12 && <4.13
39+ , bytestring
40+ , deriving-aeson
41+ , http-api-data
42+ , servant
43+ , text
44+ hs-source-dirs: src
45+ default-language: Haskell2010
dm-common/src/Common.hsnew file+2
@@ -0,0 +1,2 @@
1+module Common where
2+
src/API.hs → dm-common/src/Common/API.hsrenamed+2−2
@@ -1,8 +1,8 @@
1−module API where
1+module Common.API where
22
33import Servant.API
44
5−import Types
5+import Common.Types
66
77
88type CaptureName = Capture "name" DeploymentName
dm-common/src/Common/Types.hsnew file+80
@@ -0,0 +1,80 @@
1+module Common.Types where
2+
3+import Data.Bifunctor
4+import Data.ByteString (ByteString)
5+import Data.String
6+import Data.Text as T
7+import Data.Traversable
8+import Deriving.Aeson.Stock
9+import Web.HttpApiData
10+
11+
12+type EnvPair = (Text, Text)
13+
14+type EnvPairs = [EnvPair]
15+
16+newtype DeploymentName = DeploymentName { unDeploymentName :: Text }
17+ deriving
18+ ( Show, Read, FromJSON, ToJSON, ToHttpApiData, FromHttpApiData)
19+
20+newtype DeploymentTag = DeploymentTag { unDeploymentTag :: Text }
21+ deriving
22+ ( Show, FromJSON, ToJSON, ToHttpApiData, FromHttpApiData)
23+
24+newtype Action = Action { unAction :: Text }
25+ deriving (Show, FromJSON, ToJSON, IsString)
26+
27+newtype ArchivedFlag = ArchivedFlag { unArchivedFlag :: Bool }
28+ deriving (Show, FromJSON, ToJSON)
29+
30+data Deployment = Deployment
31+ { name :: DeploymentName
32+ , tag :: DeploymentTag
33+ , envs :: EnvPairs
34+ }
35+ deriving (Generic, Show)
36+ deriving (FromJSON, ToJSON) via Snake Deployment
37+
38+data DeploymentLog = DeploymentLog
39+ { action :: Action
40+ , deploymentTag :: DeploymentTag
41+ , deploymentEnvs :: EnvPairs
42+ , exitCode :: Int
43+ , createdAt :: Int
44+ }
45+ deriving (Generic, Show)
46+ deriving (FromJSON, ToJSON) via Snake DeploymentLog
47+
48+data DeploymentInfo = DeploymentInfo
49+ { deployment :: Deployment
50+ , logs :: [DeploymentLog]
51+ }
52+ deriving (Generic, Show)
53+ deriving (FromJSON, ToJSON) via Snake DeploymentInfo
54+
55+data DeploymentFullInfo = DeploymentFullInfo
56+ { deployment :: Deployment
57+ , archived :: Bool
58+ , createdAt :: Int
59+ , updatedAt :: Int
60+ , urls :: [(Text, Text)]
61+ }
62+ deriving (Generic, Show)
63+ deriving (FromJSON, ToJSON) via Snake DeploymentFullInfo
64+
65+data DeploymentUpdate = DeploymentUpdate
66+ { newTag :: DeploymentTag
67+ , newEnvs :: Maybe EnvPairs
68+ }
69+ deriving (Generic, Show)
70+ deriving (FromJSON, ToJSON) via Snake DeploymentUpdate
71+
72+data Status
73+ = Ok
74+ | Error
75+ deriving (Generic, Show)
76+ deriving (FromJSON, ToJSON) via Snake Status
77+
78+newtype DeploymentStatus = DeploymentStatus { status :: Status }
79+ deriving (Generic, Show)
80+ deriving (FromJSON, ToJSON) via Snake DeploymentStatus
dm-frontend/CHANGELOG.mdnew file+5
@@ -0,0 +1,5 @@
1+# Revision history for frontend
2+
3+## 0.1.0.0 -- YYYY-mm-dd
4+
5+* First version. Released on an unsuspecting world.
dm-frontend/LICENSEnew file+30
@@ -0,0 +1,30 @@
1+Copyright (c) 2020, Anisimov Nikita
2+
3+All rights reserved.
4+
5+Redistribution and use in source and binary forms, with or without
6+modification, are permitted provided that the following conditions are met:
7+
8+ * Redistributions of source code must retain the above copyright
9+ notice, this list of conditions and the following disclaimer.
10+
11+ * Redistributions in binary form must reproduce the above
12+ copyright notice, this list of conditions and the following
13+ disclaimer in the documentation and/or other materials provided
14+ with the distribution.
15+
16+ * Neither the name of Anisimov Nikita nor the names of other
17+ contributors may be used to endorse or promote products derived
18+ from this software without specific prior written permission.
19+
20+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dm-frontend/Setup.hsnew file+2
@@ -0,0 +1,2 @@
1+import Distribution.Simple
2+main = defaultMain
dm-frontend/dm-frontend.cabalnew file+26
@@ -0,0 +1,26 @@
1+-- Initial frontend.cabal generated by cabal init. For further
2+-- documentation, see http://haskell.org/cabal/users-guide/
3+
4+name: dm-frontend
5+version: 0.1.0.0
6+-- synopsis:
7+-- description:
8+license: BSD3
9+license-file: LICENSE
10+author: Anisimov Nikita
11+maintainer: anisimoff.nikita@gmail.com
12+-- copyright:
13+-- category:
14+build-type: Simple
15+extra-source-files: CHANGELOG.md
16+cabal-version: >=1.10
17+
18+executable frontend
19+ main-is: Main.hs
20+ -- other-modules:
21+ -- other-extensions:
22+ build-depends: base >=4.12 && <4.13
23+ , dm-common
24+ , reflex-dom
25+ hs-source-dirs: src
26+ default-language: Haskell2010
dm-frontend/src/Main.hsnew file+8
@@ -0,0 +1,8 @@
1+{-# LANGUAGE OverloadedStrings #-}
2+
3+module Main where
4+
5+import Reflex.Dom
6+
7+main :: IO ()
8+main = mainWidget $ text "Hello, Reflex!"
nix/default.nix+8−16
@@ -14,7 +14,7 @@
1414with {
1515 overlay = _: pkgs:
1616 with pkgs; rec {
17− dm = haskellPackages.dm-static;
17+ dm-backend = haskellPackages.dm-backend-static;
1818
1919 cacert' = cacert.overrideAttrs (o: {
2020 fixupPhase = ''
@@ -25,13 +25,13 @@ with {
2525 dms-container = dockerTools.buildImage {
2626 name = "dms-container-slim";
2727 contents =
28− [ dm git b2b-helm-tool kubernetes-helm2-bin kubectl coreutils bash openssh gnugrep cacert' ];
28+ [ dm-backend git b2b-helm-tool kubernetes-helm2-bin kubectl coreutils bash openssh gnugrep cacert' ];
2929
3030 runAsRoot = ''
3131 mkdir /tmp
3232
3333 mkdir /app
34− cp -av ${dm}/bin/dms-exe /app/dms-exe
34+ cp -av ${dm-backend}/bin/dms-exe /app/dms-exe
3535
3636 mkdir /migrations
3737 cp -av ${migrations}/* /migrations/
@@ -78,11 +78,11 @@ with {
7878
7979 dmc-container = dockerTools.buildImage {
8080 name = "dmc-container-slim";
81− contents = [ dm coreutils bash emacs vim ];
81+ contents = [ dm-backend coreutils bash emacs vim ];
8282
8383 runAsRoot = ''
8484 mkdir /app
85− cp -av ${dm}/bin/dmc-exe /app/dmc-exe
85+ cp -av ${dm-backend}/bin/dmc-exe /app/dmc-exe
8686
8787 cp ${client-cert} /cert.pem
8888 cp ${client-key} /key.pem
@@ -111,18 +111,10 @@ with {
111111
112112 haskellPackages = pkgs.haskellPackages.override {
113113 overrides = hself: hsuper: {
114+ dm-backend = (hsuper.callPackage ../default.nix { }).ghc.dm-backend;
114115
115− deriving-aeson = hsuper.callPackage (stdenv.mkDerivation ({
116− name = "deriving-aeson";
117− buildCommand = ''
118− ${hsuper.cabal2nix}/bin/cabal2nix file://${sources.deriving-aeson} > $out
119− '';
120− })) { };
121−
122− dm = hsuper.callPackage ../default.nix { };
123−
124− dm-static = haskell.lib.justStaticExecutables
125− (hsuper.callPackage ../default.nix { });
116+ dm-backend-static = haskell.lib.justStaticExecutables
117+ (hsuper.callPackage ../default.nix { }).ghc.dm-backend;
126118 };
127119 };
128120 };
release.sh−2
@@ -45,9 +45,7 @@ build_configs() {
4545 download_deploy_key $1
4646}
4747
48−
4948update_dependencies() {
50− make update-default-nix
5149 make update-b2b-helm-nix
5250}
5351
shell.nixdeleted−13
@@ -1,13 +0,0 @@
1−{ nixpkgs ? import ./nix/. {} }:
2−let
3− inherit (nixpkgs) pkgs;
4− inherit (pkgs) haskellPackages;
5−in with pkgs;
6−stdenv.mkDerivation {
7− name = "shell";
8− buildInputs = haskellPackages.dm.env.nativeBuildInputs ++ [
9− haskellPackages.pretty-show
10− haskellPackages.ghcid
11− haskellPackages.cabal-install
12− ];
13−}
src/Types.hsdeleted−140
@@ -1,140 +0,0 @@
1−module Types where
2−
3−import Data.Bifunctor
4−import Data.ByteString (ByteString)
5−import Data.String
6−import Data.Text as T
7−import Data.Traversable
8−import Database.PostgreSQL.Simple.FromField (FromField)
9−import Database.PostgreSQL.Simple.ToField (ToField)
10−import Deriving.Aeson.Stock
11−import Web.HttpApiData
12−
13−
14−type EnvPair = (Text, Text)
15−
16−type EnvPairs = [EnvPair]
17−
18−-- | Format for command arguments
19−concatPair :: EnvPair -> Text
20−concatPair (k, v) = k <> "=" <> v
21−
22−-- | Format for b2b-helm-tool / helm
23−concatPairWithAppEnv :: EnvPair -> Text
24−concatPairWithAppEnv pair = "b2b-app.env." <> concatPair pair
25−
26−-- | Format for output
27−formatEnvPairs :: EnvPairs -> Text
28−formatEnvPairs = T.unlines . fmap concatPair
29−
30−parseEnvs :: [Text] -> IO [(Text, Text)]
31−parseEnvs texts =
32− for texts $ \t ->
33− case T.findIndex (== '=') t of
34− Just i -> pure $ bimap strip (T.tail . strip) $ T.splitAt i t
35− -- ^ T.splitAt returns pair with not empty Texts, e.g. ("X", "=Y")
36− Nothing -> error $
37− "Malformed environment key-value pair " <> T.unpack t <>
38− ", should be similar to FOO=bar"
39−
40−newtype DeploymentName = DeploymentName { unDeploymentName :: Text }
41− deriving
42− ( Show, Read, FromJSON, ToJSON, FromField, ToField
43− , ToHttpApiData, FromHttpApiData)
44−
45−newtype DeploymentTag = DeploymentTag { unDeploymentTag :: Text }
46− deriving
47− ( Show, FromJSON, ToJSON, FromField, ToField
48− , ToHttpApiData, FromHttpApiData)
49−
50−newtype Action = Action { unAction :: Text }
51− deriving (Show, FromJSON, ToJSON, FromField, ToField, IsString)
52−
53−newtype ArchivedFlag = ArchivedFlag { unArchivedFlag :: Bool }
54− deriving (Show, FromJSON, ToJSON, FromField, ToField)
55−
56−data Deployment = Deployment
57− { name :: DeploymentName
58− , tag :: DeploymentTag
59− , envs :: EnvPairs
60− }
61− deriving (Generic, Show)
62− deriving (FromJSON, ToJSON) via Snake Deployment
63−
64−data DeploymentLog = DeploymentLog
65− { action :: Action
66− , deploymentTag :: DeploymentTag
67− , deploymentEnvs :: EnvPairs
68− , exitCode :: Int
69− , createdAt :: Int
70− }
71− deriving (Generic, Show)
72− deriving (FromJSON, ToJSON) via Snake DeploymentLog
73−
74−data DeploymentInfo = DeploymentInfo
75− { deployment :: Deployment
76− , logs :: [DeploymentLog]
77− }
78− deriving (Generic, Show)
79− deriving (FromJSON, ToJSON) via Snake DeploymentInfo
80−
81−data DeploymentFullInfo = DeploymentFullInfo
82− { deployment :: Deployment
83− , archived :: Bool
84− , createdAt :: Int
85− , updatedAt :: Int
86− , urls :: [(Text, Text)]
87− }
88− deriving (Generic, Show)
89− deriving (FromJSON, ToJSON) via Snake DeploymentFullInfo
90−
91−data DeploymentUpdate = DeploymentUpdate
92− { newTag :: DeploymentTag
93− , newEnvs :: Maybe EnvPairs
94− }
95− deriving (Generic, Show)
96− deriving (FromJSON, ToJSON) via Snake DeploymentUpdate
97−
98−data Status
99− = Ok
100− | Error
101− deriving (Generic, Show)
102− deriving (FromJSON, ToJSON) via Snake Status
103−
104−newtype DeploymentStatus = DeploymentStatus { status :: Status }
105− deriving (Generic, Show)
106− deriving (FromJSON, ToJSON) via Snake DeploymentStatus
107−
108−newtype ServerPort = ServerPort { unServerPort :: Int }
109− deriving (Show)
110−
111−newtype DBPoolSize = DBPoolSize { unDBPoolSize :: Int }
112− deriving (Show)
113−
114−newtype DBConnectionString = DbConnectionString
115− { unDBConnectionString :: ByteString }
116− deriving (Show)
117−
118−newtype TLSCertPath = TLSCertPath { unTLSCertPath :: ByteString }
119− deriving (Show)
120−
121−newtype TLSKeyPath = TLSKeyPath { unTLSKeyPath :: ByteString }
122− deriving (Show)
123−
124−newtype TLSStorePath = TLSStore { unTLSStorePath :: ByteString }
125− deriving (Show)
126−
127−newtype ProjectName = ProjectName { unProjectName :: Text }
128− deriving (Show)
129−
130−newtype Domain = Domain { unDomain :: Text }
131− deriving (Show)
132−
133−newtype Namespace = Namespace { unNamespace :: Text }
134− deriving (Show)
135−
136−newtype ArchiveRetention = ArchiveRetention { unArchiveRetention :: Int }
137− deriving (Show)
138−
139−newtype Command = Command { unCommand :: Text }
140− deriving (Show)