Skip to content

Commit d2ff73a

Browse files
First commit
0 parents  commit d2ff73a

File tree

6 files changed

+111
-0
lines changed

6 files changed

+111
-0
lines changed

.gitignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Compiled Object files, Static and Dynamic libs (Shared Objects)
2+
*.o
3+
*.a
4+
*.so
5+
6+
# Folders
7+
_obj
8+
_test
9+
bin
10+
11+
# Architecture specific extensions/prefixes
12+
*.[568vq]
13+
[568vq].out
14+
15+
*.cgo1.go
16+
*.cgo2.c
17+
_cgo_defun.c
18+
_cgo_gotypes.go
19+
_cgo_export.*
20+
21+
_testmain.go
22+
23+
*.exe
24+
*.test
25+
*.prof

Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM golang:1.15.1-alpine3.12 AS build-env
2+
3+
WORKDIR /tmp/simple-go-app
4+
5+
COPY . .
6+
7+
RUN CGO_ENABLED=0 GOOS=linux go build
8+
9+
FROM scratch
10+
COPY --from=build-env /tmp/simple-go-app/simple-web-app /app/simple-web-app
11+
12+
EXPOSE 8080
13+
CMD ["/app/simple-web-app"]

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# A sample GO web application with Dockerfile
2+
3+
See also https://github.com/kostis-codefresh/simple-kubernetes-deployment
4+

codefresh.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
version: "1.0"
2+
stages:
3+
- "clone"
4+
- "build"
5+
- "metadata"
6+
7+
steps:
8+
clone:
9+
title: "Cloning repository"
10+
type: "git-clone"
11+
repo: "kostis-codefresh/simple-web-app"
12+
revision: '${{CF_REVISION}}'
13+
stage: "clone"
14+
15+
build:
16+
title: "Building Docker image"
17+
type: "build"
18+
image_name: "kostiscodefresh/simple-web-app"
19+
working_directory: "${{clone}}"
20+
tags:
21+
- "latest"
22+
- '${{CF_SHORT_REVISION}}'
23+
dockerfile: "Dockerfile"
24+
stage: "build"
25+
registry: dockerhub
26+
get_step_info:
27+
title: Get Github token
28+
stage: "metadata"
29+
image: 'codefresh/cli'
30+
commands:
31+
- cf_export GITHUB_TOKEN=$(codefresh get context github-1 --decrypt -o yaml | yq -y .spec.data.auth.password)
32+
enrich-image:
33+
title: Add PR info
34+
type: image-enricher
35+
stage: "metadata"
36+
arguments:
37+
IMAGE: docker.io/kostiscodefresh/simple-web-app:latest
38+
BRANCH: '${{CF_BRANCH}}'
39+
REPO: 'kostis-codefresh/simple-web-app'
40+
GITHUB_TOKEN: '${{GITHUB_TOKEN}}'
41+
42+
43+

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/kostis-codefresh/simple-web-app
2+
3+
go 1.13

simple-web-server.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
)
7+
8+
func indexHandler(w http.ResponseWriter, r *http.Request) {
9+
fmt.Fprintf(w, "I am a GO application running inside Docker.")
10+
11+
}
12+
13+
func healthHandler(w http.ResponseWriter, r *http.Request) {
14+
fmt.Fprintf(w, "OK\n")
15+
16+
}
17+
18+
func main() {
19+
fmt.Println("Simple web server is starting on port 8080...")
20+
http.HandleFunc("/", indexHandler)
21+
http.HandleFunc("/health", healthHandler)
22+
http.ListenAndServe(":8080", nil)
23+
}

0 commit comments

Comments
 (0)