Skip to content

Instantly share code, notes, and snippets.

@Itch3f
Forked from smagch/.dockerignore
Created September 10, 2017 22:32
Show Gist options
  • Select an option

  • Save Itch3f/e2a6a6ae4e1a4faf301ead7a3e855fc1 to your computer and use it in GitHub Desktop.

Select an option

Save Itch3f/e2a6a6ae4e1a4faf301ead7a3e855fc1 to your computer and use it in GitHub Desktop.

Revisions

  1. @smagch smagch revised this gist Nov 7, 2014. 8 changed files with 158 additions and 0 deletions.
    1 change: 1 addition & 0 deletions .dockerignore
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    .git
    1 change: 1 addition & 0 deletions .gitignore
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    param.json
    9 changes: 9 additions & 0 deletions Dockerfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    FROM golang:1.3.3

    RUN mkdir -p /go/src/app
    WORKDIR /go/src/app
    COPY . /go/src/app

    EXPOSE 8080
    RUN ["go", "install", "."]
    CMD ["app"]
    3 changes: 3 additions & 0 deletions Dockerrun.aws.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    {
    "AWSEBDockerrunVersion": "1"
    }
    29 changes: 29 additions & 0 deletions create.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    #!/bin/bash
    set -e

    # ensure param.json exists
    if [ ! -f param.json ]; then
    cat <<EOUSAGE
    param.json file should exist.
    You can copy param.example.json
    EOUSAGE
    exit 1
    fi

    find_param() {
    local keyName="$1"
    cat param.json | jq -r --arg keyName $keyName \
    '.[] | select(.ParameterKey == $keyName) | .ParameterValue'
    }

    BUCKET_NAME=$(find_param S3Bucket)
    KEY_NAME=$(find_param S3Key)

    # upload git archive to S3
    git archive --format zip HEAD | aws s3 cp - s3://${BUCKET_NAME}/${KEY_NAME}

    aws cloudformation create-stack \
    --stack-name my-stack \
    --template-body file://eb.json \
    --region ap-northeast-1 \
    --parameters file://param.json
    79 changes: 79 additions & 0 deletions eb.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,79 @@
    {
    "AWSTemplateFormatVersion" : "2010-09-09",
    "Description" : "AWS CloudFormation Docker Test",
    "Parameters" : {
    "Subnets": {
    "Type": "CommaDelimitedList",
    "Description": "Subnets"
    },
    "VpcId": {
    "Type": "String",
    "Description": "VPC Id"
    },
    "S3Bucket": {
    "Type": "String",
    "Description": "S3 Bucket name"
    },
    "S3Key": {
    "Type": "String",
    "Description": "S3 Key name"
    }
    },
    "Resources" : {
    "SampleApplication" : {
    "Type" : "AWS::ElasticBeanstalk::Application",
    "Properties" : {
    "Description" : "AWS Elastic Beanstalk Docker Sample Application",
    "ApplicationVersions" : [{
    "VersionLabel" : "Initial Version",
    "Description" : "Version 1.0",
    "SourceBundle" : {
    "S3Bucket" : {"Ref": "S3Bucket"},
    "S3Key": {"Ref": "S3Key"}
    }
    }]
    }
    },
    "SampleEnvironment" : {
    "Type" : "AWS::ElasticBeanstalk::Environment",
    "Properties" : {
    "ApplicationName" : { "Ref" : "SampleApplication" },
    "Description" : "AWS Elastic Beanstalk Environment running Docker Sample Application",
    "SolutionStackName" : "64bit Amazon Linux 2014.09 v1.0.9 running Docker 1.2.0",
    "VersionLabel" : "Initial Version",
    "OptionSettings": [
    {
    "Namespace": "aws:autoscaling:launchconfiguration",
    "OptionName": "InstanceType",
    "Value": "t2.micro"
    },
    {
    "Namespace": "aws:ec2:vpc",
    "OptionName": "VPCId",
    "Value": { "Ref" : "VpcId" }
    },
    {
    "Namespace": "aws:ec2:vpc",
    "OptionName": "Subnets",
    "Value" : {
    "Fn::Join": [",", { "Ref" : "Subnets" }]
    }
    },
    {
    "Namespace": "aws:ec2:vpc",
    "OptionName": "ELBSubnets",
    "Value" : {
    "Fn::Select": ["0", {"Ref" : "Subnets" }]
    }
    }
    ]
    }
    }
    },
    "Outputs" : {
    "URL" : {
    "Description" : "The URL of the Elastic Beanstalk environment",
    "Value" : { "Fn::Join" : [ "", [ "http://", { "Fn::GetAtt" : ["SampleEnvironment", "EndpointURL"] }]]}
    }
    }
    }
    18 changes: 18 additions & 0 deletions main.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    package main

    import (
    "fmt"
    "html"
    "log"
    "net/http"
    )

    func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
    }

    func main() {
    http.HandleFunc("/", handler)
    log.Println("start server")
    log.Fatal(http.ListenAndServe(":8080", nil))
    }
    18 changes: 18 additions & 0 deletions param.example.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    [
    {
    "ParameterKey": "VpcId",
    "ParameterValue": "default-vpc-id"
    },
    {
    "ParameterKey": "Subnets",
    "ParameterValue": "subnets-1, subnet-2"
    },
    {
    "ParameterKey": "S3Key",
    "ParameterValue": "docker-sample.zip"
    },
    {
    "ParameterKey": "S3Bucket",
    "ParameterValue": "smagch-docker"
    }
    ]
  2. @smagch smagch created this gist Nov 7, 2014.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    # AWS: CloudFormation with Elastic Beanstalk, Docker Go web app