~zacbrown/api.zacbrown.org-infra

892fa1547929bb009d63df7e916ea48013d3f8a9 — Zac Brown 11 months ago d795470 master
Add process supervisor 'immortal' to ensure the app stays up.
M deploy-ec2-cloudinit/files/build_app => deploy-ec2-cloudinit/files/build_app +2 -0
@@ 3,6 3,7 @@
export GOROOT=/opt/go
export PATH=$PATH:$GOROOT/bin/
export HOME=/home/ec2-user
export GOPATH=$HOME/go

cd $HOME



@@ 23,4 24,5 @@ cd $GIT_REPO_NAME
go get -u
go build

# Move the config file over
mv /tmp/config.toml $HOME/
\ No newline at end of file

A deploy-ec2-cloudinit/files/run.yml => deploy-ec2-cloudinit/files/run.yml +8 -0
@@ 0,0 1,8 @@
cmd: /home/ec2-user/go/bin/api.zacbrown.org /home/ec2-user/config.toml
cwd: /home/ec2-user
log:
    file: /var/log/api.zacbrown.org.log
    age: 10  # seconds
    num: 7   # int
    size: 1  # MegaBytes
wait: 1

M deploy-ec2-cloudinit/files/start_app => deploy-ec2-cloudinit/files/start_app +3 -1
@@ 2,5 2,7 @@

export HOME=/home/ec2-user
export GOPATH=$HOME/go
export GOROOT=/opt/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

$GOPATH/bin/api.zacbrown.org $HOME/config.toml
\ No newline at end of file
immortal -c /tmp/run.yml
\ No newline at end of file

M deploy-ec2-cloudinit/files/update_system => deploy-ec2-cloudinit/files/update_system +4 -1
@@ 1,4 1,7 @@
#!/bin/bash -e

yum update -y
yum install -y git
\ No newline at end of file

curl -s https://packagecloud.io/install/repositories/immortal/immortal/script.rpm.sh | sudo bash
yum install -y git immortal


M deploy-ec2-cloudinit/index.ts => deploy-ec2-cloudinit/index.ts +19 -1
@@ 65,6 65,18 @@ const keypair = new aws.ec2.KeyPair("keypair", {
    publicKey: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD2uYdBlc7pPZvZ0bJDfRuqj4JEEhhTlGXYIZm0/K613S01d7WsxfXcJJOuy/ZrtGluBAtHVMDHfeD4eSrISstI5BxkFJILKLsw6yyAGDmNHvs+bMG3a6+9PWc8MFUlbJ5c33331Rb69I209Zem8kHuL62GBLIqgWVmYWL60zMTYvCSNCpFYOxzhdCAF8yDWtG6tI0DU6C+bXsD3c7guzxTqzehnfFg1IdcLdEH9ITtFFJnmvm4JIcWA7BohgY1UdXuNV0d1yGy3c3UtZOxHfZdzw6QERLXQ8X6sSupEA0dRZ/PpEQxrkWHnpDbAhLt3Cl5e83yUIyT+57/UkoXWrab",
});

function renderAwsConfig(config: { iamAccessKeyId: any; iamAccessKeySecret: any; awsRegion: any; }) {
    let c = {
        AwsConfig: {
            IamAccessKeyId: config.iamAccessKeyId,
            IamAccessKeySecret: config.iamAccessKeySecret,
            Region: config.awsRegion
        }
    };

    return Promise.resolve(toml.stringify(c))
}

// Create our AMI.
const awsInstanceWeb = new aws.ec2.Instance("webServer", {
    ami: amiId.id,


@@ 108,7 120,7 @@ const awsInstanceWeb = new aws.ec2.Instance("webServer", {
            "build_app": {
                files: {
                    "/tmp/config.toml": {
                        content: renderConfigFile("./files/config.toml", config),
                        content: renderAwsConfig(config),
                        mode: "000400",
                        owner: "root",
                        group: "root",


@@ 133,6 145,12 @@ const awsInstanceWeb = new aws.ec2.Instance("webServer", {
                        mode: "000500",
                        owner: "root",
                        group: "root",
                    },
                    "/tmp/run.yml": {
                        content: renderConfigFile("./files/run.yml", config),
                        mode: "000400",
                        owner: "root",
                        group: "root",
                    }
                },
                commands: {