Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
e498283
platform-terraform: initial commit
TalzelAti Nov 20, 2019
56a0cc1
build: default.nix, haskell,nix: added platform-terraform
TalzelAti Nov 20, 2019
d32ea5a
Terraform.hs: progress toward a deployment of an instance with an ssh
TalzelAti Nov 27, 2019
41e9cae
Terraform.hs: more progression
TalzelAti Dec 1, 2019
afc224e
Terraform.hs: finished basic configuration for one instance with ssh.…
TalzelAti Dec 1, 2019
03e9b0f
terraform.hs: code correction
TalzelAti Dec 2, 2019
002454c
platform-deployment: initial
TalzelAti Dec 2, 2019
eb35b88
platform-deployment: compiling test interpreter that only prints mess…
TalzelAti Dec 3, 2019
4564470
platform-deployment: moved Test.hs into a dedicated folder
TalzelAti Dec 3, 2019
5111624
platform-deployment: moved Test.hs into a dedicated folder
TalzelAti Dec 3, 2019
18d0033
Deployment: AMI.hs: added poc of templating and multiline strings
TalzelAti Dec 4, 2019
3fb6aee
AMI.hs: added templates for all pieces of aws in terraform
TalzelAti Dec 4, 2019
78a4e3e
platform-deployment: splitted to different modules
TalzelAti Dec 4, 2019
8ee2b32
platform-deployment: first compiled version of ami interpreter. doesn…
TalzelAti Dec 5, 2019
db6c756
deployment: Template.hs: aligned code
TalzelAti Dec 5, 2019
d008ca8
platform-deployment: fixed bug in ginger rendering
TalzelAti Dec 5, 2019
7ffcfbd
Template.hs: fixed bug preventing instances from creating public dns
TalzelAti Dec 8, 2019
a2e652c
build: added nix configuration for platform-deployment
TalzelAti Dec 10, 2019
d1684f9
AMI.hs: added working ssh example
TalzelAti Dec 10, 2019
9517d2d
AMI.hs, cabal file: removed simplessh deps
TalzelAti Dec 10, 2019
1379fdb
Template.hs: eliminated interpolation warnings
TalzelAti Dec 11, 2019
ec0b199
AMI.hs: added docker initialization commands, and built small docker …
TalzelAti Dec 11, 2019
62b8c01
AMI.hs: added command to save ami from instance started by terraform
TalzelAti Dec 11, 2019
c252827
platform-deployment: renamed AMIConfig to terraform config
TalzelAti Dec 12, 2019
df7b6e3
platform-deployment: wrapped template config with ami config
TalzelAti Dec 12, 2019
6a616ce
platform-deployment: AMI.hs: added support for mounts and partially s…
TalzelAti Dec 16, 2019
1e446c6
AMI.hs: all sorts of changes
TalzelAti Dec 18, 2019
ec3f712
AMI.hs: deleteed useless code
TalzelAti Dec 18, 2019
1a5fa6a
Deployment.hs: fixed the high level language abit
TalzelAti Dec 18, 2019
5a7336a
platform-deployment: added terraform interpreter skeleton. compiles, …
TalzelAti Dec 19, 2019
0b95031
platform-deployment: added a terraform interpreter
TalzelAti Dec 22, 2019
bd09180
platform-deployment: added automated disk mounting generated terrafor…
TalzelAti Dec 24, 2019
0f65f71
platform-deployment: delete public key value from code. now imported …
TalzelAti Dec 24, 2019
ba7b18a
terraform-deployment: added ginger template argument for ebs vol name
TalzelAti Dec 24, 2019
6822e4c
platform-deployment: add docker install provisioner as a null resource
TalzelAti Dec 24, 2019
818c768
platform-deployment: commiting partial work about declaring secrets
TalzelAti Dec 26, 2019
5140014
platform-deployment: added single secret
TalzelAti Dec 29, 2019
96a3dc4
platform-deployment: secrets now work
TalzelAti Dec 29, 2019
1f96543
platform-deployment: added support for folders and secrets attachment…
TalzelAti Dec 30, 2019
56848aa
platform-deployment: added support for docker run
TalzelAti Dec 30, 2019
1dfd230
plaform-deployment: added option for args on docker run, and a more c…
TalzelAti Dec 30, 2019
46fadf2
platform-deployment: added CLI and added some documentation
TalzelAti Dec 30, 2019
5d88934
platform-deployment: fixed all warnings
TalzelAti Dec 30, 2019
77e2758
platform-deployment: Terraform: Template: changed foldl1 to foldl bec…
TalzelAti Jan 1, 2020
194d83f
platform-deployment: Terraform: added deployment tests cases and impr…
TalzelAti Jan 1, 2020
75bc853
platform-deployment: secrets are not hardcoded anymore
TalzelAti Jan 1, 2020
bc860d6
platform-deployment: Readme updated
TalzelAti Jan 8, 2020
4082397
platform-deployment: Readme updated
TalzelAti Jan 8, 2020
7da604a
platform-deployment: Readme updated
TalzelAti Jan 8, 2020
e3ad701
platform-deployment: code indentation
TalzelAti Jan 8, 2020
13466a0
platform-deployment: code indentation
TalzelAti Jan 8, 2020
f306145
platform-deployment: removed useless boolean values in the code
TalzelAti Jan 12, 2020
170d2af
platform-deployment: Deployment.hs:
TalzelAti Jan 12, 2020
bf475f0
platform-deployment: reformatted code
TalzelAti Jan 12, 2020
fe0ed37
platform-deployment: code formatted
TalzelAti Jan 12, 2020
0692ec3
playform-deployment: readme edited
TalzelAti Jan 12, 2020
fe4220c
platform-deployment: readme edited
TalzelAti Jan 12, 2020
ccc34ef
platform-deployment: CR fixes
TalzelAti Jan 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ let
platform-process
platform-packaging
platform-visual
platform-terraform
platform-deployment
]);

in
Expand Down
28 changes: 19 additions & 9 deletions build/haskell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,34 @@ rec {
rev = "64e7bfb3abcad278e6160cd411abdd21a485a671";
};

terraformHsSrc = fetchGit {
url = https://github.com/atidot/terraform-hs;
rev = "4815301f4d5cf8343907ea55e41f4f491930dc69";
};

platformTypesSrc = ../platform-types;
platformDSLSrc = ../platform-dsl;
platformAWSSrc = ../platform-aws;
platformKubeSrc = ../platform-kube;
platformProcessSrc = ../platform-process;
platformPackagingSrc = ../platform-packaging;
platformVisualSrc = ../platform-visual;
platformTerraformSrc = ../platform-terraform;
platformDeploymentSrc = ../platform-deployment;

projectPackages = hspkgs: {
executor = ease hspkgs.executor;
stratosphere = hspkgs.callCabal2nix "stratosphere" "${stratosphereSrc}" {};
platform-types = hspkgs.callCabal2nix "platform-types" "${platformTypesSrc}" {};
platform-dsl = hspkgs.callCabal2nix "platform-dsl" "${platformDSLSrc}" {};
platform-aws = hspkgs.callCabal2nix "platform-aws" "${platformAWSSrc}" {};
platform-kube = hspkgs.callCabal2nix "platform-kube" "${platformKubeSrc}" {};
platform-packaging = hspkgs.callCabal2nix "platform-packaging" "${platformPackagingSrc}" {};
platform-process = hspkgs.callCabal2nix "platform-process" "${platformProcessSrc}" {};
platform-visual = hspkgs.callCabal2nix "platform-visual" "${platformVisualSrc}" {};
executor = ease hspkgs.executor;
stratosphere = hspkgs.callCabal2nix "stratosphere" "${stratosphereSrc}" {};
terraform-hs = hspkgs.callCabal2nix "terraform-hs" "${terraformHsSrc}" {};
platform-types = hspkgs.callCabal2nix "platform-types" "${platformTypesSrc}" {};
platform-dsl = hspkgs.callCabal2nix "platform-dsl" "${platformDSLSrc}" {};
platform-aws = hspkgs.callCabal2nix "platform-aws" "${platformAWSSrc}" {};
platform-kube = hspkgs.callCabal2nix "platform-kube" "${platformKubeSrc}" {};
platform-packaging = hspkgs.callCabal2nix "platform-packaging" "${platformPackagingSrc}" {};
platform-process = hspkgs.callCabal2nix "platform-process" "${platformProcessSrc}" {};
platform-visual = hspkgs.callCabal2nix "platform-visual" "${platformVisualSrc}" {};
platform-terraform = hspkgs.callCabal2nix "platform-terraform" "${platformTerraformSrc}" {};
platform-deployment = hspkgs.callCabal2nix "platform-deployment" "${platformDeploymentSrc}" {};
};

packages = haskellPackages.override (old: {
Expand Down
3 changes: 3 additions & 0 deletions platform-deployment/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.stack-work/
platform-deployment.cabal
*~
30 changes: 30 additions & 0 deletions platform-deployment/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright Author name here (c) 2019

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of Author name here nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
77 changes: 77 additions & 0 deletions platform-deployment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# platform-deployment

## Intro

Allows us to declare a deployment inside an aws instance, with dockers, disks and secrets declarative management

Platform deployment package holds two parts:

1. Deployment-dsl - High language implemented with free monad, that describes the things we need in order to deploy software configuration (containers, secrets and data). [Here](src/Atidot/Platform/Deployment.hs)
1. Interpreters for deployment dsl - there are two interpreters
1. 1. AMI - starts a machine in aws with terraform configuration, then apply changes, and eventually, saves an AMI containing all the changes supplied. This is dynamic, which means that the machine state is changed after applying each line. [Here](src/Atidot/Platform/Deployment/Interpreter/AMI.hs)
1. 1. Terraform - Generates a terraform deployment file, that once applied, will start and then configure a full machine, on `terraform init`. This is static, which means that the interpreter is run, and then a file is generated. There is no AMI ready at the end of the interpreter run. It is more mature of the two. [here](https://github.com/Atidot/platform/blob/deployment/platform-deployment/src/Atidot/Platform/Deployment/Interpreter/Terraform.hs)

## Terraform requirements and notes

* [Terraform](https://www.terraform.io/) needs to be installed.
* In the terraform configuration, there is an sh key [path](src/Atidot/Platform/Deployment/Interpreter/AMI/Types/Default.hs#L23). It is needed to be supplied for the remote provisioners and for ssh connection into the deployed machine
* AWS credentials for configuring the aws cli are needed but are prompted during `terraform init`
* AWS EBS volumes are needed in order for mounting to work properly
* Volume is needed to be created before running the interpreter.It’s (Volume) name/id should be be added to the configuration [Here](src/Atidot/Platform/Deployment/Interpreter/Terraform/Template.hs#L26)
* Terraform deploys a single virtual machine with network components required for ssh connection into that machine. Then it uses a series of remote provisioners to change the state of the machine:
* 1. Installation of software and secrets initialization [Here](src/Atidot/Platform/Deployment/Interpreter/Terraform/Template.hs#L85)
* 1. secrets mounting code [Here](src/Atidot/Platform/Deployment/Interpreter/Terraform/Template.hs#L110)
* 1. Mounting and pulling dockers [Here](src/Atidot/Platform/Deployment/Interpreter/Terraform/Template.hs#L156)
* 1. Running dockers (Run command in the deployment DSL) [Here](src/Atidot/Platform/Deployment/Interpreter/Terraform/Template.hs#L189)
* In order to run new scripts, they should be added in [Main](app/Main.hs#L27)
Nes,nesa,std,sat,cdne - are error checking scripts, they should fail.
* All secrets used must be properly defined in advance in the AWS secrets manager

## Next Steps

* In order to avoid credentials for aws-cli completely, we can add an IAM role for the AMI [Here](https://dzone.com/articles/aws-secret-manager-protect-your-secrets-in-applica)
* CLI שrgument for terraform configurations (using json, from file?)
* Separate failed scripts (Nes,nesa,std,sat,cdne) to tests, to ensure that behavior is stable
* Instead of provisioner for running dockers, a provisioner for preparing a script that run dockers on computer start
* Better name giving to the ebs volumes (will be relevant if we want more than one volume) [Here](src/Atidot/Platform/Deployment/Interpreter/Terraform/Template.hs#L44)
* Improving the description of secrets in the dsl (they come in tuples at least, and are in a json format),

## example script

``` haskell
nsss :: DeploymentM Bool
nsss = do
secret <- secret "tutorials/MyFirstTutorialSecret"
dir <- mount "data"
c <- container "hello-world"
attachSecret secret c
attachVolume dir c
execute [] c []
return b
```

This script Declares:

1. A secret
2. An external disk "data"
3. a container named hello world
4. attaches the secret to the container
5. attaches the mount to the container
6. executes the container

## How to Run

``` bash
$ cd ../build
..
$ make shell
... # in the newly opened nix shell
$ platform-deployment-exe --script nsss
{initializes terraform and generates files from example}
$ cd terraform_dep
...
$ ls
aws_cli_config.tf example.tf
$ terraform apply # applies genetated configuration
...
```
35 changes: 35 additions & 0 deletions platform-deployment/app/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{-# LANGUAGE DeriveGeneric #-}
module Main where

import "optparse-generic" Options.Generic
import "data-default" Data.Default
import Atidot.Platform.Deployment
import Atidot.Platform.Deployment.Interpreter.Terraform
import Atidot.Platform.Deployment.Interpreter.AMI.Types

data CLI = CLI
{script :: String
} deriving (Generic, Show)

instance ParseRecord CLI


main :: IO ()
main = do
x <- script <$> getRecord "Platform Deployment"
case lookup x scripts of
Just s -> runTerraform def s
Nothing -> error $ unlines
[ "script '" ++ x ++ "' not found"
, "available scripts are: " ++ show (map fst scripts)
]

scripts =
[ ("nsss",nsss)
, ("kiss",kiss)
, ("nes",noneExistentSecret)
, ("nesa",noneExistentSecretAttached)
, ("sdt", secretDeclaredTwice)
, ("sat",secretAttachedTwice)
, ("cdne",containerDoesNotExists)
]
114 changes: 114 additions & 0 deletions platform-deployment/platform-deployment.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
cabal-version: 1.12

-- This file has been generated from package.yaml by hpack version 0.31.0.
--
-- see: https://github.com/sol/hpack
--
-- hash: 61e356af67999cee1223314d87fdfdd592f960368b933db1b8f345df60667e82

name: platform-deployment
version: 0.1.0.0
description: Please see the README on GitHub at <https://github.com/githubuser/platform-deployment#readme>
homepage: https://github.com/githubuser/platform-deployment#readme
bug-reports: https://github.com/githubuser/platform-deployment/issues
author: Author name here
maintainer: example@example.com
copyright: 2019 Author name here
license: BSD3
license-file: LICENSE
build-type: Simple
extra-source-files:
README.md
ChangeLog.md

source-repository head
type: git
location: https://github.com/githubuser/platform-deployment

library
exposed-modules:
Atidot.Platform.Deployment
Atidot.Platform.Deployment.Interpreter.AMI
Atidot.Platform.Deployment.Interpreter.AMI.Template
Atidot.Platform.Deployment.Interpreter.AMI.Types
Atidot.Platform.Deployment.Interpreter.AMI.Types.Default
Atidot.Platform.Deployment.Interpreter.AMI.Types.Types
Atidot.Platform.Deployment.Interpreter.Terraform
Atidot.Platform.Deployment.Interpreter.Terraform.Template
Atidot.Platform.Deployment.Interpreter.Test
Atidot.Platform.Deployment.Interpreter.Utils
other-modules:
Paths_platform_deployment
hs-source-dirs:
src
default-extensions: PackageImports OverloadedStrings ScopedTypeVariables
ghc-options: -Wall -Werror
build-depends:
aeson
, base >=4.7 && <5
, containers
, data-default
, directory
, exceptions
, free
, ginger
, mtl
, optparse-generic
, raw-strings-qq
, text
, turtle
, uuid
default-language: Haskell2010

executable platform-deployment-exe
main-is: Main.hs
other-modules:
Paths_platform_deployment
hs-source-dirs:
app
default-extensions: PackageImports OverloadedStrings ScopedTypeVariables
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
aeson
, base >=4.7 && <5
, containers
, data-default
, directory
, exceptions
, free
, ginger
, mtl
, optparse-generic
, platform-deployment
, raw-strings-qq
, text
, turtle
, uuid
default-language: Haskell2010

test-suite platform-deployment-test
type: exitcode-stdio-1.0
main-is: Spec.hs
other-modules:
Paths_platform_deployment
hs-source-dirs:
test
default-extensions: PackageImports OverloadedStrings ScopedTypeVariables
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
aeson
, base >=4.7 && <5
, containers
, data-default
, directory
, exceptions
, free
, ginger
, mtl
, optparse-generic
, platform-deployment
, raw-strings-qq
, text
, turtle
, uuid
default-language: Haskell2010
Loading