Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
Signed-off-by: Stephanie <yangcao@redhat.com>
  • Loading branch information
yangcao77 committed Apr 6, 2022
0 parents commit 8c27a59
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 0 deletions.
25 changes: 25 additions & 0 deletions outerloop-deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
kind: Deployment
apiVersion: apps/v1
metadata:
name: my-go
spec:
replicas: 1
selector:
matchLabels:
app: go-app
template:
metadata:
labels:
app: go-app
spec:
containers:
- name: my-go
image: go-image:latest
ports:
- name: http
containerPort: 8081
protocol: TCP
resources:
limits:
memory: "1024Mi"
cpu: "500m"
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.odo/env
.odo/odo-file-index.json
main
.idea/
.DS_Store
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM golang:1.16-alpine

WORKDIR /app

COPY go.mod ./
RUN go mod download

COPY *.go ./

RUN go build -o /main

EXPOSE 8081

CMD [ "/main" , "-p=8081"]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# devfile-sample-go-basic
41 changes: 41 additions & 0 deletions devfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
schemaVersion: 2.2.0
metadata:
name: go
language: go
projectType: go
tags:
- Go
version: 1.0.0
provider: Red Hat
supportUrl: https://github.com/devfile-samples/devfile-support#support-information
attributes:
alpha.dockerimage-port: 8081
parent:
id: go
registryUrl: "https://registry.devfile.io"
components:
- name: outerloop-build
image:
imageName: go-image:latest
dockerfile:
uri: docker/Dockerfile
buildContext: .
rootRequired: false
- name: outerloop-deploy
kubernetes:
uri: outerloop-deploy.yaml
commands:
- id: build-image
apply:
component: outerloop-build
- id: deployk8s
apply:
component: outerloop-deploy
- id: deploy
composite:
commands:
- build-image
- deployk8s
group:
kind: deploy
isDefault: true
14 changes: 14 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM golang:1.16-alpine

WORKDIR /app

COPY go.mod ./
RUN go mod download

COPY *.go ./

RUN go build -o /main

EXPOSE 8081

CMD [ "/main" , "-p=8081"]
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/schultzp2020/devfile-starter-projects/go

go 1.16
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"
"net/http"
"flag"
)
var port = flag.Int("p", 8080, "server port")

func main() {
flag.Parse()
http.HandleFunc("/", HelloServer)
http.ListenAndServe(fmt.Sprintf("0.0.0.0:%d", *port), nil)
}

func HelloServer(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %s!", r.URL.Path[1:])
}

0 comments on commit 8c27a59

Please sign in to comment.