Compare commits

...

7 Commits

Author SHA1 Message Date
Stefan Prodan
4ed9271783 Release v1.3.1 2018-10-27 11:50:14 +03:00
Stefan Prodan
97157694be Add logs to Docker build GitHub action 2018-10-27 11:48:32 +03:00
Stefan Prodan
bf92728234 Generate Github actions CI pipeline
- add custom Dockerfile
- use GitHub actions env vars as docker build args
- remove .gh from Makefile and Dockerfile in destination project
2018-10-27 11:41:52 +03:00
Stefan Prodan
f7c8061ac0 Bump version in GitHub Actions docs 2018-10-26 19:07:00 +03:00
Stefan Prodan
943f4e26ab Release v1.3.1 2018-10-26 19:05:17 +03:00
Stefan Prodan
f44909ef77 Add golang tools GitHub Action 2018-10-26 18:23:02 +03:00
Stefan Prodan
1af24bd3cd Run gofmt 2018-10-26 18:20:54 +03:00
26 changed files with 230 additions and 65 deletions

View File

@@ -1,17 +1,15 @@
FROM docker:stable
LABEL "name"="Docker tag and push action"
LABEL "maintainer"="Stefan Prodan <support@gweave.works>"
LABEL "maintainer"="Stefan Prodan <support@weave.works>"
LABEL "version"="1.0.0"
LABEL "com.github.actions.icon"="terminal"
LABEL "com.github.actions.color"="gray-dark"
LABEL "com.github.actions.icon"="package"
LABEL "com.github.actions.color"="green"
LABEL "com.github.actions.name"="Docker Publish"
LABEL "com.github.actions.description"="This is an Action to run docker tag and push commands."
RUN apk update \
&& apk add --no-cache ca-certificates bash git curl \
&& (apk info | xargs -n1 -I{} apk --quiet add {}-doc); true \
RUN apk add --no-cache ca-certificates bash git curl \
&& rm -rf /var/cache/apk/*
COPY entrypoint.sh /entrypoint.sh

View File

@@ -4,8 +4,6 @@ set -o errexit
set -o nounset
set -o pipefail
echo "Starting tag and push for image ${DOCKER_IMAGE} release ${GITHUB_REF}"
DOCKER_TAG="latest"
if [[ "${GITHUB_REF}" == "refs/tags"* ]]; then
DOCKER_TAG=$(echo ${GITHUB_REF} | rev | cut -d/ -f1 | rev)
@@ -13,7 +11,15 @@ else
DOCKER_TAG=$(echo ${GITHUB_REF} | rev | cut -d/ -f1 | rev)-$(echo ${GITHUB_SHA} | head -c7)
fi
docker tag app ${DOCKER_IMAGE}:${DOCKER_TAG}
docker push ${DOCKER_IMAGE}:${DOCKER_TAG}
if [[ "$1" == "build" ]]; then
docker build -t ${DOCKER_IMAGE}:${DOCKER_TAG} \
--build-arg REPOSITORY=${GITHUB_REPOSITORY} \
--build-arg SHA=${GITHUB_SHA} -f $2 .
echo "Docker image tagged as ${DOCKER_IMAGE}:${DOCKER_TAG}"
fi
if [[ "$1" == "push" ]]; then
docker push ${DOCKER_IMAGE}:${DOCKER_TAG}
echo "Docker image pushed to ${DOCKER_IMAGE}:${DOCKER_TAG}"
fi
echo "Docker image pushed to ${DOCKER_IMAGE}:${DOCKER_TAG}"

20
.github/actions/golang/Dockerfile vendored Normal file
View File

@@ -0,0 +1,20 @@
FROM golang:1.10
LABEL "name"="golang tools action"
LABEL "maintainer"="Stefan Prodan <support@weave.works>"
LABEL "version"="1.0.0"
LABEL "com.github.actions.icon"="code"
LABEL "com.github.actions.color"="green-dark"
LABEL "com.github.actions.name"="Go Tools"
LABEL "com.github.actions.description"="This is an Action to run go and dep commands."
ENV DEP_VERSION="v0.5.0"
RUN curl -fL -o /usr/local/bin/dep https://github.com/golang/dep/releases/download/${DEP_VERSION}/dep-linux-amd64 \
&& chmod +x /usr/local/bin/dep
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

26
.github/actions/golang/entrypoint.sh vendored Executable file
View File

@@ -0,0 +1,26 @@
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
set -e
APP_DIR="/go/src/github.com/${GITHUB_REPOSITORY}/"
mkdir -p ${APP_DIR} && cp -r ./ ${APP_DIR} && cd ${APP_DIR}
if [[ "$1" == "fmt" ]]; then
echo "Running go fmt"
files=$(gofmt -l $(find . -type f -name '*.go' -not -path "./vendor/*") 2>&1)
if [ "$files" ]; then
echo "These files did not pass the gofmt check:"
echo ${files}
exit 1
fi
fi
if [[ "$1" == "test" ]]; then
echo "Running go test"
go test $(go list ./... | grep -v /vendor/) -race -coverprofile=coverage.txt -covermode=atomic
cat coverage.txt
fi

30
.github/main.workflow vendored
View File

@@ -1,21 +1,35 @@
workflow "Publish container" {
on = "push"
resolves = ["Docker tag and push"]
resolves = ["Push"]
}
action "Test and build" {
uses = "actions/docker/cli@master"
args = "build -t app -f Dockerfile.ci ."
action "Lint" {
uses = "./.github/actions/golang"
args = "fmt"
}
action "Docker login" {
needs = ["Test and build"]
action "Test" {
needs = ["Lint"]
uses = "./.github/actions/golang"
args = "test"
}
action "Build" {
needs = ["Test"]
uses = "./.github/actions/docker"
secrets = ["DOCKER_IMAGE"]
args = ["build", "Dockerfile.gh"]
}
action "Login" {
needs = ["Build"]
uses = "actions/docker/login@master"
secrets = ["DOCKER_USERNAME", "DOCKER_PASSWORD"]
}
action "Docker tag and push" {
needs = ["Docker login"]
action "Push" {
needs = ["Login"]
uses = "./.github/actions/docker"
secrets = ["DOCKER_IMAGE"]
args = "push"
}

39
Dockerfile.gh Normal file
View File

@@ -0,0 +1,39 @@
FROM golang:1.11 as builder
ARG REPOSITORY
ARG SHA
RUN mkdir -p /go/src/github.com/${REPOSITORY}/
WORKDIR /go/src/github.com/${REPOSITORY}
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build \
-ldflags "-s -w -X github.com/${REPOSITORY}/pkg/version.REVISION=${SHA}" \
-a -installsuffix cgo -o podinfo ./cmd/podinfo \
&& mv podinfo /usr/local/bin/podinfo
RUN CGO_ENABLED=0 GOOS=linux go build \
-ldflags "-s -w -X github.com/${REPOSITORY}/pkg/version.REVISION=${SHA}" \
-a -installsuffix cgo -o podcli ./cmd/podcli \
&& mv podcli /usr/local/bin/podcli
FROM alpine:3.8
RUN addgroup -S app \
&& adduser -S -g app app \
&& apk --no-cache add \
curl openssl netcat-openbsd
WORKDIR /home/app
COPY --from=builder /usr/local/bin/podinfo .
COPY --from=builder /usr/local/bin/podcli /usr/local/bin/podcli
COPY ./ui ./ui
RUN chown -R app:app ./
USER app
CMD ["./podinfo"]

17
Makefile.gh Normal file
View File

@@ -0,0 +1,17 @@
DOCKER_IMAGE?=stefanprodan/k8s-podinfo
DOCKER_TAG?=$(shell git symbolic-ref --short HEAD)
GIT_REPOSITORY?=stefanprodan/k8s-podinfo
GIT_SHA:=$(shell git describe --dirty --always)
.PHONY: all
all: test build
.PHONY: test
test:
go test ./...
.PHONY: build
build:
docker build -t $(DOCKER_IMAGE):$(DOCKER_TAG) \
--build-arg REPOSITORY=${GIT_REPOSITORY} \
--build-arg SHA=${GIT_SHA} -f Dockerfile.gh .

View File

@@ -1,6 +1,6 @@
apiVersion: v1
version: 1.3.0
appVersion: 1.3.0
version: 1.3.1
appVersion: 1.3.1
name: podinfo
engine: gotpl
description: Podinfo Helm chart for Kubernetes

View File

@@ -12,7 +12,7 @@ faults:
image:
repository: quay.io/stefanprodan/podinfo
tag: 1.3.0
tag: 1.3.1
pullPolicy: IfNotPresent
service:

View File

@@ -102,9 +102,8 @@ func runCodeInit(cmd *cobra.Command, args []string) error {
}
}
files := []string{"Gopkg.toml", "Gopkg.lock", "Dockerfile.ci"}
files := []string{"Gopkg.toml", "Gopkg.lock"}
for _, file := range files {
if err := copyFile(path.Join(tmpPath, versionName, file), path.Join(codeProjectPath, file)); err != nil {
log.Fatalf("Error: %s", err)
os.Exit(1)
@@ -124,6 +123,42 @@ func runCodeInit(cmd *cobra.Command, args []string) error {
}
}
projFrom := "stefanprodan/k8s-podinfo"
projTo := fmt.Sprintf("%s/%s", codeGitUser, codeProjectName)
makeFiles := []string{"Makefile.gh", "Dockerfile.gh"}
for _, file := range makeFiles {
fileContent, err := ioutil.ReadFile(path.Join(tmpPath, versionName, file))
if err != nil {
log.Fatalf("Error: %s", err)
os.Exit(1)
}
destFile := strings.Replace(file, ".gh", "", -1)
newContent := strings.Replace(string(fileContent), projFrom, projTo, -1)
err = ioutil.WriteFile(path.Join(codeProjectPath, destFile), []byte(newContent), os.ModePerm)
if err != nil {
log.Fatalf("Error: %s", err)
os.Exit(1)
}
}
workflows := []string{".github/main.workflow"}
for _, file := range workflows {
fileContent, err := ioutil.ReadFile(path.Join(codeProjectPath, file))
if err != nil {
log.Fatalf("Error: %s", err)
os.Exit(1)
}
newContent := strings.Replace(string(fileContent), "Dockerfile.gh", "Dockerfile", -1)
err = ioutil.WriteFile(path.Join(codeProjectPath, file), []byte(newContent), os.ModePerm)
if err != nil {
log.Fatalf("Error: %s", err)
os.Exit(1)
}
}
err = gitPush()
if err != nil {
log.Fatalf("git push error: %s", err)
@@ -136,7 +171,7 @@ func runCodeInit(cmd *cobra.Command, args []string) error {
func gitPush() error {
cmd := exec.Command("sh", "-c", "git add . && git commit -m \"init\" && git push")
output , err := cmd.Output()
output, err := cmd.Output()
if err != nil {
return err
}
@@ -168,7 +203,7 @@ func replaceImports(projectPath string, pkgFrom string, pkgTo string) error {
matches := regexImport.FindAllString(content, -1)
isExists := false
isReplacable:
isReplaceable:
for _, each := range matches {
for _, eachLine := range strings.Split(each, "\n") {
matchesInline := regexImportedPackage.FindAllString(eachLine, -1)
@@ -179,7 +214,7 @@ func replaceImports(projectPath string, pkgFrom string, pkgTo string) error {
for _, eachSubline := range matchesInline {
if strings.Contains(eachSubline, pkgFrom) {
isExists = true
break isReplacable
break isReplaceable
}
}
}
@@ -204,10 +239,6 @@ func replaceImports(projectPath string, pkgFrom string, pkgTo string) error {
fmt.Println("ERROR", err.Error())
}
//for _, path := range found {
// fmt.Printf("found in %s\n", path)
//}
if len(found) == 0 {
fmt.Println("Nothing replaced")
} else {

View File

@@ -21,11 +21,11 @@ Clone your private repository (preferable in your `$GOPATH`) and initialize podi
git clone https://github.com/stefanprodan/demo-app
cd demo-app
podcli code init demo-app --git-user=stefanprodan --version=v1.3.0
podcli code init demo-app --git-user=stefanprodan --version=v1.3.1
```
The above command does the following:
* downloads podinfo source code v1.3.0 from GitHub
* downloads podinfo source code v1.3.1 from GitHub
* replaces golang import with your git username and project name
* commits and pushes the code to GitHub

Binary file not shown.

Binary file not shown.

View File

@@ -3,9 +3,9 @@ entries:
ambassador:
- apiVersion: v1
appVersion: 0.29.0
created: 2018-10-26T15:31:43.278264+03:00
created: 2018-10-27T11:49:54.792088+03:00
description: A Helm chart for Datawire Ambassador
digest: cc98bdb12f62987f1b67abe5c07b020c53b4744890c96a6029ade34b5db2a81c
digest: f82505d3abaff6d039e189787e22e44dc4a9fde81976bf7771ed664aeabc75a1
engine: gotpl
maintainers:
- email: stefanprodan@users.noreply.github.com
@@ -19,9 +19,9 @@ entries:
grafana:
- apiVersion: v1
appVersion: "1.0"
created: 2018-10-26T15:31:43.279121+03:00
created: 2018-10-27T11:49:54.79284+03:00
description: A Helm chart for Kubernetes
digest: 67c3b569c35f08119d9019ca40d6923536e5b2030a377ee48c013dd94c931dad
digest: ee244448260eda8029a182d603715c48c97b1cc00c376d84f67a2e0b0653ed50
name: grafana
urls:
- https://stefanprodan.github.io/k8s-podinfo/grafana-0.1.0.tgz
@@ -29,9 +29,9 @@ entries:
loadtest:
- apiVersion: v1
appVersion: "1.0"
created: 2018-10-26T15:31:43.279354+03:00
created: 2018-10-27T11:49:54.793039+03:00
description: Hey load test Helm chart for Kubernetes
digest: a6090952068f5350c25e597879deb6f92edac04f85dc6ddfb469e50d59d721ab
digest: 413fbb941e72ebe8d94f2ce1ae42946aa68d88276e969ed2f12595af8da1cbf4
name: loadtest
urls:
- https://stefanprodan.github.io/k8s-podinfo/loadtest-0.1.0.tgz
@@ -39,17 +39,33 @@ entries:
ngrok:
- apiVersion: v1
appVersion: "1.0"
created: 2018-10-26T15:31:43.279638+03:00
created: 2018-10-27T11:49:54.793328+03:00
description: A Ngrok Helm chart for Kubernetes
digest: 0d3c902456901657fbe676279abed5d0d1adc8c039fa0c595cda311780faf3f9
digest: 5678de7c8aac246df507f40b3f4f8fd6d06f4447e636398819a232dd26e1fc41
name: ngrok
urls:
- https://stefanprodan.github.io/k8s-podinfo/ngrok-0.1.0.tgz
version: 0.1.0
podinfo:
- apiVersion: v1
appVersion: 1.3.1
created: 2018-10-27T11:49:54.804223+03:00
description: Podinfo Helm chart for Kubernetes
digest: d863e2511ec5f0a7705ae12886aa9cfb40ab1c07d2ab6afd69bba69b39abcf21
engine: gotpl
home: https://github.com/stefanprodan/k8s-podinfo
maintainers:
- email: stefanprodan@users.noreply.github.com
name: stefanprodan
name: podinfo
sources:
- https://github.com/stefanprodan/k8s-podinfo
urls:
- https://stefanprodan.github.io/k8s-podinfo/podinfo-1.3.1.tgz
version: 1.3.1
- apiVersion: v1
appVersion: 1.3.0
created: 2018-10-26T15:31:43.288141+03:00
created: 2018-10-27T11:49:54.803825+03:00
description: Podinfo Helm chart for Kubernetes
digest: 7111b868a11014ab56da11b7edbea9ce0d1a483500969252f66c9ae1943bac67
engine: gotpl
@@ -65,7 +81,7 @@ entries:
version: 1.3.0
- apiVersion: v1
appVersion: 1.2.1
created: 2018-10-26T15:31:43.286784+03:00
created: 2018-10-27T11:49:54.802868+03:00
description: Podinfo Helm chart for Kubernetes
digest: c750c1d4a7606a06cd89ae4433431c7e3ecf2ccc9a0e5f6baa26095397bd72da
engine: gotpl
@@ -81,7 +97,7 @@ entries:
version: 1.2.1
- apiVersion: v1
appVersion: 1.2.0
created: 2018-10-26T15:31:43.285692+03:00
created: 2018-10-27T11:49:54.80169+03:00
description: Podinfo Helm chart for Kubernetes
digest: 24460e15e6da77106eb5212cd683dc2c1d4404b927be6b9f0c89433ba865722e
engine: gotpl
@@ -97,7 +113,7 @@ entries:
version: 1.2.0
- apiVersion: v1
appVersion: 1.1.0
created: 2018-10-26T15:31:43.28491+03:00
created: 2018-10-27T11:49:54.800849+03:00
description: Podinfo Helm chart for Kubernetes
digest: 973d60c629d7ae476776098ad6b654d78d91f91b3faa8bc016b94c73c42be094
engine: gotpl
@@ -113,7 +129,7 @@ entries:
version: 1.1.0
- apiVersion: v1
appVersion: 1.0.0
created: 2018-10-26T15:31:43.283974+03:00
created: 2018-10-27T11:49:54.799786+03:00
description: Podinfo Helm chart for Kubernetes
digest: 82068727ba5b552341b14a980e954e27a8517f0ef76aab314c160b0f075e6de4
engine: gotpl
@@ -129,7 +145,7 @@ entries:
version: 1.0.0
- apiVersion: v1
appVersion: 0.6.0
created: 2018-10-26T15:31:43.283093+03:00
created: 2018-10-27T11:49:54.798697+03:00
description: Podinfo Helm chart for Kubernetes
digest: bd25a710eddb3985d3bd921a11022b5c68a04d37cf93a1a4aab17eeda35aa2f8
engine: gotpl
@@ -145,7 +161,7 @@ entries:
version: 0.2.2
- apiVersion: v1
appVersion: 0.5.1
created: 2018-10-26T15:31:43.282334+03:00
created: 2018-10-27T11:49:54.797853+03:00
description: Podinfo Helm chart for Kubernetes
digest: 631ca3e2db5553541a50b625f538e6a1f2a103c13aa8148fdd38baf2519e5235
engine: gotpl
@@ -161,7 +177,7 @@ entries:
version: 0.2.1
- apiVersion: v1
appVersion: 0.5.0
created: 2018-10-26T15:31:43.281504+03:00
created: 2018-10-27T11:49:54.797046+03:00
description: Podinfo Helm chart for Kubernetes
digest: dfe7cf44aef0d170549918b00966422a07e7611f9d0081fb34f5b5beb0641c00
engine: gotpl
@@ -177,7 +193,7 @@ entries:
version: 0.2.0
- apiVersion: v1
appVersion: 0.3.0
created: 2018-10-26T15:31:43.280579+03:00
created: 2018-10-27T11:49:54.796003+03:00
description: Podinfo Helm chart for Kubernetes
digest: 4865a2d8b269cf453935cda9661c2efb82c16411471f8c11221a6d03d9bb58b1
engine: gotpl
@@ -194,9 +210,9 @@ entries:
podinfo-istio:
- apiVersion: v1
appVersion: 1.2.1
created: 2018-10-26T15:31:43.291242+03:00
created: 2018-10-27T11:49:54.808061+03:00
description: Podinfo Helm chart for Istio
digest: cb444efd6e693842296e8832c3c4830752513e69b8e3f589254b74df7e506d8b
digest: 4f47d5373ee5a8cec6bacb61cdd1ac5bad650a62381721ea0178a568ead2b539
engine: gotpl
home: https://github.com/stefanprodan/k8s-podinfo
maintainers:
@@ -210,7 +226,7 @@ entries:
version: 1.2.1
- apiVersion: v1
appVersion: 1.2.0
created: 2018-10-26T15:31:43.2907+03:00
created: 2018-10-27T11:49:54.807262+03:00
description: Podinfo Helm chart for Istio
digest: 8115e72f232f82eb3e6da1965364cfede7c069f95a627dddac45cfbe6cb90dc4
engine: gotpl
@@ -226,7 +242,7 @@ entries:
version: 1.2.0
- apiVersion: v1
appVersion: 1.1.0
created: 2018-10-26T15:31:43.28986+03:00
created: 2018-10-27T11:49:54.806166+03:00
description: Podinfo Helm chart for Istio
digest: bcceb63ff780a8f0ba0b30997040e4e82170f9cce17c26ec817648ed024c83f5
engine: gotpl
@@ -242,7 +258,7 @@ entries:
version: 0.2.0
- apiVersion: v1
appVersion: 0.6.0
created: 2018-10-26T15:31:43.288999+03:00
created: 2018-10-27T11:49:54.805124+03:00
description: Podinfo Helm chart for Istio
digest: f12f8aa1eca1328e9eaa30bd757f6ed3ff97205e2bf016a47265bc2de6a63d8f
engine: gotpl
@@ -256,4 +272,4 @@ entries:
urls:
- https://stefanprodan.github.io/k8s-podinfo/podinfo-istio-0.1.0.tgz
version: 0.1.0
generated: 2018-10-26T15:31:43.277729+03:00
generated: 2018-10-27T11:49:54.791526+03:00

Binary file not shown.

Binary file not shown.

BIN
docs/podinfo-1.3.1.tgz Normal file

Binary file not shown.

Binary file not shown.

View File

@@ -3,8 +3,8 @@ package api
import (
"net/http"
"net/http/httptest"
"testing"
"regexp"
"testing"
)
func TestDelayHandler(t *testing.T) {

View File

@@ -3,8 +3,8 @@ package api
import (
"net/http"
"net/http/httptest"
"testing"
"strings"
"testing"
)
func TestEchoHandler(t *testing.T) {

View File

@@ -2,7 +2,6 @@ package api
import (
"net/http"
)
func (s *Server) echoHeadersHandler(w http.ResponseWriter, r *http.Request) {

View File

@@ -3,8 +3,8 @@ package api
import (
"time"
"go.uber.org/zap"
"github.com/gorilla/mux"
"go.uber.org/zap"
)
func NewMockServer() *Server {

View File

@@ -2,7 +2,6 @@ package api
import (
"net/http"
)
func (s *Server) panicHandler(w http.ResponseWriter, r *http.Request) {

View File

@@ -16,5 +16,5 @@ func (s *Server) statusHandler(w http.ResponseWriter, r *http.Request) {
return
}
s.JSONResponseCode(w, r, map[string]int{"status": code}, code)
s.JSONResponseCode(w, r, map[string]int{"status": code}, code)
}

View File

@@ -7,8 +7,8 @@ import (
"net/http"
"path"
"go.uber.org/zap"
"github.com/gorilla/mux"
"go.uber.org/zap"
)
func (s *Server) storeWriteHandler(w http.ResponseWriter, r *http.Request) {
@@ -26,7 +26,7 @@ func (s *Server) storeWriteHandler(w http.ResponseWriter, r *http.Request) {
s.ErrorResponse(w, r, "writing file failed", http.StatusInternalServerError)
return
}
s.JSONResponseCode(w, r, map[string]string{"hash": hash}, http.StatusAccepted)
s.JSONResponseCode(w, r, map[string]string{"hash": hash}, http.StatusAccepted)
}
func (s *Server) storeReadHandler(w http.ResponseWriter, r *http.Request) {

View File

@@ -1,4 +1,4 @@
package version
var VERSION = "1.3.0"
var VERSION = "1.3.1"
var REVISION = "unknown"