Skip to content

Commit

Permalink
added step to parse out deployment version
Browse files Browse the repository at this point in the history
  • Loading branch information
mchmarny committed Oct 4, 2019
1 parent 851da2b commit d8a461e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/github-action-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Build image
uses: actions/docker/cli@master
with:
args: "build --tag gcr.io/${{ secrets.GCP_PROJECT }}/greeter ./github-action-deploy"
args: "build --tag gcr.io/${{ secrets.GCP_PROJECT }}/greeter:${{ github.ref }} ./github-action-deploy"

- name: Authenticate to GCP
uses: actions/gcloud/auth@master
Expand All @@ -35,6 +35,9 @@ jobs:
entrypoint: sh
args: -c "docker push gcr.io/${{ secrets.GCP_PROJECT }}/greeter"

- name: Prepare service manifest
run: sed -e 's/PROJECT_ID/${{ secrets.GCP_PROJECT }}/g; s/APP_NAME/greeter/g; s/TAG_REF/${{ github.ref }}/g' github-action-deploy/template.yaml > github-action-deploy/service.yaml

- name: Install kubectl and deploy service
uses: actions/gcloud/cli@master
with:
Expand Down
12 changes: 10 additions & 2 deletions github-action-deploy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (
)

const (
defaultPort = "8080"
portVariableName = "PORT"
defaultPort = "8080"
portVariableName = "PORT"
releaseVariableName = "RELEASE"
)

var (
Expand Down Expand Up @@ -60,10 +61,16 @@ func statusHandler(c *gin.Context) {
return
}

releaseVersion := os.Getenv(releaseVariableName)
if releaseVersion == "" {
releaseVersion = "v0.0.0"
}

c.JSON(http.StatusOK, &Status{
ID: id.String(),
Message: c.Param("msg"),
RequestOn: time.Now(),
Release: releaseVersion,
})
}

Expand All @@ -72,4 +79,5 @@ type Status struct {
ID string `json:"id"`
Message string `json:"msg,omitempty"`
RequestOn time.Time `json:"on"`
Release string `json:"rel"`
}
9 changes: 0 additions & 9 deletions github-action-deploy/service.yaml

This file was deleted.

12 changes: 12 additions & 0 deletions github-action-deploy/template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: APP_NAME
spec:
template:
spec:
containers:
- image: gcr.io/PROJECT_ID/APP_NAME:TAG_REF
env:
- name: RELEASE
value: "TAG_REF"

0 comments on commit d8a461e

Please sign in to comment.