Skip to content

Commit 82cfa3b

Browse files
committed
feat: service discovery by default
This change enables service discovery by default for all apps. Service discovery alows apps within an environment to communicate with each other without having to traverse the internet (traffic is routed internally within the VPC). To access a service via its service discovery endpoint, you can make a request like: ```golang resp, _ := http.Get(fmt.Sprintf("http://%s.%s", appName, os.Getenv("ECS_APP_DISCOVERY_ENDPOINT")) ``` Or, with only the project name: ```golang resp, _ := http.Get(fmt.Sprintf("http://%s.%s.local", appName, projectName)) ``` Or, without the string interpolation: ```golang # Making a request to app `api` in project `kudos` resp, _ := http.Get("http://api.kudos.local") ``` The same address works across environments, since the requests are scoped to services within one environment. __ Why not just .local ?__ A couple of reasons to go for the `.{project}.local` scheme, rather than just `.local` or just `.{project}`. The reason for not using just `.local` is just to reduce the chance of a namespace colision if another project is using the same VPC. The reason for not just going with `.{project}` is in case the project name matches an existing TLD. That'd be confusing behavior. The `.local` TLD doesn't seem to exist. __ Why make this default for every service? __ You can't add service discovery after the fact, unfortunately. The only sensible thing is to just enable it by default. In the future, we can offer a disable knob, but it's very cheap (less than a dollar per month per env) - so isn't a huge burden for customers who end up not using it. resolves #599
1 parent b94b910 commit 82cfa3b

File tree

18 files changed

+265
-48
lines changed

18 files changed

+265
-48
lines changed

e2e/multi-app-project/back-end/Dockerfile

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
1-
FROM nginx
1+
# We specify the base image we need for our
2+
# go application
3+
FROM golang:1.13 AS builder
4+
# We create an /app directory within our
5+
# image that will hold our application source
6+
# files
7+
RUN mkdir /app
8+
# We copy everything in the root directory
9+
# into our /app directory
10+
ADD . /app
11+
# We specify that we now wish to execute
12+
# any further commands inside our /app
13+
# directory
14+
WORKDIR /app
15+
# Avoid the GoProxy
16+
ENV GOPROXY=direct
17+
# we run go build to compile the binary
18+
# executable of our Go program
19+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o e2e-service ./
220

3-
COPY nginx.conf /etc/nginx/nginx.conf
21+
# To make our images smaller, use alpine and copy in the service binary.
22+
FROM alpine:latest
23+
# Install certs
24+
RUN apk --no-cache add ca-certificates
25+
# Copy the binary from the builder image
26+
COPY --from=builder /app ./
27+
# Make the binary executable
28+
RUN chmod +x ./e2e-service
29+
# Start the service
30+
ENTRYPOINT ["./e2e-service"]
31+
# The service runs on port 80
32+
EXPOSE 80
433

5-
RUN mkdir -p /www/data/back-end
6-
COPY index.html /www/data/back-end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module github.com/aws/amazon-ecs-cli-v2/e2e/multi-app-project/back-end
2+
3+
go 1.13
4+
5+
require github.com/julienschmidt/httprouter v1.3.0 // indirect
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
2+
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=

e2e/multi-app-project/back-end/index.html

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package main
2+
3+
import (
4+
"log"
5+
"net/http"
6+
7+
"github.com/julienschmidt/httprouter"
8+
)
9+
10+
// HealthCheck just returns true if the service is up.
11+
func HealthCheck(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
12+
log.Println("🚑 healthcheck ok!")
13+
w.WriteHeader(http.StatusOK)
14+
}
15+
16+
// SimpleGet just returns true no matter what
17+
func SimpleGet(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
18+
log.Println("Get Succeeded")
19+
w.WriteHeader(http.StatusOK)
20+
w.Write([]byte("back-end"))
21+
}
22+
23+
// ServiceDiscoveryGet just returns true no matter what
24+
func ServiceDiscoveryGet(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
25+
log.Println("Get on ServiceDiscovery endpoint Succeeded")
26+
w.WriteHeader(http.StatusOK)
27+
w.Write([]byte("back-end-service-discovery"))
28+
}
29+
30+
func main() {
31+
router := httprouter.New()
32+
router.GET("/back-end/", SimpleGet)
33+
router.GET("/service-discovery/", ServiceDiscoveryGet)
34+
35+
// Health Check
36+
router.GET("/", HealthCheck)
37+
38+
log.Fatal(http.ListenAndServe(":80", router))
39+
}

e2e/multi-app-project/back-end/nginx.conf

Lines changed: 0 additions & 17 deletions
This file was deleted.

e2e/multi-app-project/front-end/Dockerfile

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
1-
FROM nginx
1+
# We specify the base image we need for our
2+
# go application
3+
FROM golang:1.13 AS builder
4+
# We create an /app directory within our
5+
# image that will hold our application source
6+
# files
7+
RUN mkdir /app
8+
# We copy everything in the root directory
9+
# into our /app directory
10+
ADD . /app
11+
# We specify that we now wish to execute
12+
# any further commands inside our /app
13+
# directory
14+
WORKDIR /app
15+
# Avoid the GoProxy
16+
ENV GOPROXY=direct
17+
# we run go build to compile the binary
18+
# executable of our Go program
19+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o e2e-service ./
220

3-
COPY nginx.conf /etc/nginx/nginx.conf
21+
# To make our images smaller, use alpine and copy in the service binary.
22+
FROM alpine:latest
23+
# Install certs
24+
RUN apk --no-cache add ca-certificates
25+
# Copy the binary from the builder image
26+
COPY --from=builder /app ./
27+
# Make the binary executable
28+
RUN chmod +x ./e2e-service
29+
# Start the service
30+
ENTRYPOINT ["./e2e-service"]
31+
# The service runs on port 80
32+
EXPOSE 80
433

5-
RUN mkdir -p /www/data/front-end
6-
COPY index.html /www/data/front-end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module github.com/aws/amazon-ecs-cli-v2/e2e/multi-app-project/front-end
2+
3+
go 1.13
4+
5+
require github.com/julienschmidt/httprouter v1.3.0 // indirect
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
2+
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=

e2e/multi-app-project/front-end/index.html

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)