diff --git a/.github/workflows/github-action-deploy.yml b/.github/workflows/github-action-deploy.yml index a35f674..99876a4 100644 --- a/.github/workflows/github-action-deploy.yml +++ b/.github/workflows/github-action-deploy.yml @@ -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 @@ -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: diff --git a/github-action-deploy/main.go b/github-action-deploy/main.go index 2945253..e09fd49 100644 --- a/github-action-deploy/main.go +++ b/github-action-deploy/main.go @@ -12,8 +12,9 @@ import ( ) const ( - defaultPort = "8080" - portVariableName = "PORT" + defaultPort = "8080" + portVariableName = "PORT" + releaseVariableName = "RELEASE" ) var ( @@ -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, }) } @@ -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"` } diff --git a/github-action-deploy/service.yaml b/github-action-deploy/service.yaml deleted file mode 100644 index 2c92166..0000000 --- a/github-action-deploy/service.yaml +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: serving.knative.dev/v1 -kind: Service -metadata: - name: greeter -spec: - template: - spec: - containers: - - image: gcr.io/cloudylabs/greeter diff --git a/github-action-deploy/template.yaml b/github-action-deploy/template.yaml new file mode 100644 index 0000000..1fc9879 --- /dev/null +++ b/github-action-deploy/template.yaml @@ -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"