diff --git a/.gitignore b/.gitignore index ba22c99a..a1d1ecbb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .idea *.sw? .vscode +*.exe +rest-example \ No newline at end of file diff --git a/_examples/rest/Dockerfile b/_examples/rest/Dockerfile new file mode 100644 index 00000000..2d68abf8 --- /dev/null +++ b/_examples/rest/Dockerfile @@ -0,0 +1,9 @@ +FROM scratch + +WORKDIR /app + +COPY rest-example rest-example + +EXPOSE 8080 + +ENTRYPOINT [ "/app/rest-example" ] \ No newline at end of file diff --git a/_examples/rest/buildspec.yml b/_examples/rest/buildspec.yml new file mode 100644 index 00000000..452abf98 --- /dev/null +++ b/_examples/rest/buildspec.yml @@ -0,0 +1,27 @@ +version: 0.2 + +phases: + pre_build: + commands: + - echo Logging in to Amazon ECR... + - aws --version + - aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin 012345678910.dkr.ecr.us-west-2.amazonaws.com + - REPOSITORY_URI=631637231789.dkr.ecr.eu-west-1.amazonaws.com/che-ict + - COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7) + - IMAGE_TAG=${COMMIT_HASH:=latest} + build: + commands: + - echo Build started on `date` + - echo Building the Docker image... + - docker build -t $REPOSITORY_URI:latest . + - docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG + post_build: + commands: + - echo Build completed on `date` + - echo Pushing the Docker images... + - docker push $REPOSITORY_URI:latest + - docker push $REPOSITORY_URI:$IMAGE_TAG + - echo Writing image definitions file... + - printf '[{"name":"hello-world","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json +artifacts: + files: imagedefinitions.json \ No newline at end of file diff --git a/_examples/rest/main.go b/_examples/rest/main.go index 9e1ed36c..e5c8e79a 100644 --- a/_examples/rest/main.go +++ b/_examples/rest/main.go @@ -1,4 +1,3 @@ -// // REST // ==== // This example demonstrates a HTTP REST web service with some fixture data. @@ -36,7 +35,6 @@ // // $ curl http://localhost:3333/articles // [{"id":"2","title":"sup"},{"id":"97","title":"awesomeness"}] -// package main import ( @@ -46,6 +44,7 @@ import ( "fmt" "math/rand" "net/http" + "os" "strings" "github.com/go-chi/chi/v5" @@ -112,7 +111,13 @@ func main() { return } - http.ListenAndServe(":3333", r) + httpPort := os.Getenv("HTTP_PORT") + if httpPort == "" { + httpPort = "8080" + } + + fmt.Printf("Listening on port: " + httpPort + "\n") + http.ListenAndServe(":"+httpPort, r) } func ListArticles(w http.ResponseWriter, r *http.Request) {