Skip to content

Instantly share code, notes, and snippets.

@euank
Last active March 14, 2023 23:40
Show Gist options
  • Select an option

  • Save euank/2d5a7bc74dc56f502c30 to your computer and use it in GitHub Desktop.

Select an option

Save euank/2d5a7bc74dc56f502c30 to your computer and use it in GitHub Desktop.

Revisions

  1. euank revised this gist Aug 13, 2015. 1 changed file with 0 additions and 8 deletions.
    8 changes: 0 additions & 8 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -1,8 +0,0 @@
    .PHONY: all clean

    all:
    go build -o main ./main.go
    docker build -t euank/play:2015-08-10 .

    clean:
    rm -f main
  2. euank created this gist Aug 13, 2015.
    10 changes: 10 additions & 0 deletions Dockerfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    FROM golang:1.4

    COPY entrypoint.sh /entrypoint.sh
    COPY main.go main.go
    RUN go build -o main main.go
    RUN chmod +x /entrypoint.sh

    EXPOSE 8080
    ENTRYPOINT ["/entrypoint.sh"]
    CMD ["./main"]
    8 changes: 8 additions & 0 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    .PHONY: all clean

    all:
    go build -o main ./main.go
    docker build -t euank/play:2015-08-10 .

    clean:
    rm -f main
    4 changes: 4 additions & 0 deletions entrypoint.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    #!/bin/sh
    export HOST=$(curl --retry 5 --connect-timeout 3 -s 169.254.169.254/latest/meta-data/local-hostname)
    export LOCAL_IP=$(curl --retry 5 --connect-timeout 3 -s 169.254.169.254/latest/meta-data/local-ipv4)
    exec "$@"
    19 changes: 19 additions & 0 deletions main.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    package main

    import (
    "encoding/json"
    "log"
    "net/http"
    "os"
    )

    func main() {
    log.Fatal(http.ListenAndServe(":8080", http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
    resp.Header().Set("Content-Type", "application/json")
    body, err := json.Marshal(map[string]string{"hostname": os.Getenv("HOST"), "localIp": os.Getenv("LOCAL_IP")})
    if err != nil {
    panic(err)
    }
    resp.Write(body)
    })))
    }
    12 changes: 12 additions & 0 deletions task-definition.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    {
    "family": "test-hostenv-entrypoint",
    "containerDefinitions": [{
    "name": "test",
    "image": "euank/play:2015-08-10",
    "memory": 50,
    "portMappings": [{
    "containerPort": 8080,
    "hostPort": 8080
    }]
    }]
    }