From ae1e1c055696e7f2fd2db0038e0fbb162d352ea4 Mon Sep 17 00:00:00 2001 From: Lee Brown Date: Tue, 6 Aug 2019 12:29:00 -0800 Subject: [PATCH] fixing build cache target name --- .gitlab-ci.yml | 2 +- cmd/web-api/handlers/check.go | 19 +++++++++++++++++-- cmd/web-app/handlers/check.go | 22 +++++++++++++++++++--- cmd/web-app/handlers/routes.go | 1 - tools/devops/cmd/cicd/service_build.go | 8 ++++---- 5 files changed, 41 insertions(+), 11 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 75707a3..d2bf084 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -32,7 +32,7 @@ cache: .build_tmpl: &build_tmpl <<: *job_tmpl script: - - 'EMAIL_SENDER=$EMAIL_SENDER devops build -service=${SERVICE} -project=${PROJECT_NAME} -env=${TARGET_ENV}' + - 'devops build -service=${SERVICE} -project=${PROJECT_NAME} -env=${TARGET_ENV}' .deploy_tmpl: &deploy_tmpl <<: *job_tmpl diff --git a/cmd/web-api/handlers/check.go b/cmd/web-api/handlers/check.go index 7d0e571..35083a7 100644 --- a/cmd/web-api/handlers/check.go +++ b/cmd/web-api/handlers/check.go @@ -3,6 +3,7 @@ package handlers import ( "context" "net/http" + "os" "geeks-accelerator/oss/saas-starter-kit/internal/platform/web" "github.com/jmoiron/sqlx" @@ -33,13 +34,27 @@ func (c *Check) Health(ctx context.Context, w http.ResponseWriter, r *http.Reque return errors.Wrap(err, "Redis failed") } - status := struct { + data := struct { Status string `json:"status"` + CiCommitRefName string `json:"ci-commit-ref-name,omitempty"` + CiCommitRefSlug string `json:"ci-commit-ref-slug,omitempty"` + CiCommitSha string `json:"ci-commit-sha,omitempty"` + CiCommitTag string `json:"ci-commit-tag,omitempty"` + CiCommitTitle string `json:"ci-commit-title,omitempty"` + CiJobId string `json:"ci-commit-job-id,omitempty"` + CiPipelineId string `json:"ci-commit-pipeline-id,omitempty"` }{ Status: "ok", + CiCommitRefName: os.Getenv("CI_COMMIT_REF_NAME"), + CiCommitRefSlug: os.Getenv("CI_COMMIT_REF_SLUG"), + CiCommitSha: os.Getenv("CI_COMMIT_SHA"), + CiCommitTag: os.Getenv("CI_COMMIT_TAG"), + CiCommitTitle: os.Getenv("CI_COMMIT_TITLE"), + CiJobId : os.Getenv("CI_COMMIT_JOB_ID"), + CiPipelineId: os.Getenv("CI_COMMIT_PIPELINE_ID"), } - return web.RespondJson(ctx, w, status, http.StatusOK) + return web.RespondJson(ctx, w, data, http.StatusOK) } // Ping validates the service is ready to accept requests. diff --git a/cmd/web-app/handlers/check.go b/cmd/web-app/handlers/check.go index 8950df4..f7b3c0a 100644 --- a/cmd/web-app/handlers/check.go +++ b/cmd/web-app/handlers/check.go @@ -3,6 +3,7 @@ package handlers import ( "context" "net/http" + "os" "geeks-accelerator/oss/saas-starter-kit/internal/platform/web" "github.com/jmoiron/sqlx" @@ -14,7 +15,6 @@ import ( type Check struct { MasterDB *sqlx.DB Redis *redis.Client - Renderer web.Renderer // ADD OTHER STATE LIKE THE LOGGER IF NEEDED. } @@ -34,8 +34,24 @@ func (c *Check) Health(ctx context.Context, w http.ResponseWriter, r *http.Reque return errors.Wrap(err, "Redis failed") } - data := map[string]interface{}{ - "Status": "ok", + data := struct { + Status string `json:"status"` + CiCommitRefName string `json:"ci-commit-ref-name,omitempty"` + CiCommitRefSlug string `json:"ci-commit-ref-slug,omitempty"` + CiCommitSha string `json:"ci-commit-sha,omitempty"` + CiCommitTag string `json:"ci-commit-tag,omitempty"` + CiCommitTitle string `json:"ci-commit-title,omitempty"` + CiJobId string `json:"ci-commit-job-id,omitempty"` + CiPipelineId string `json:"ci-commit-pipeline-id,omitempty"` + }{ + Status: "ok", + CiCommitRefName: os.Getenv("CI_COMMIT_REF_NAME"), + CiCommitRefSlug: os.Getenv("CI_COMMIT_REF_SLUG"), + CiCommitSha: os.Getenv("CI_COMMIT_SHA"), + CiCommitTag: os.Getenv("CI_COMMIT_TAG"), + CiCommitTitle: os.Getenv("CI_COMMIT_TITLE"), + CiJobId : os.Getenv("CI_COMMIT_JOB_ID"), + CiPipelineId: os.Getenv("CI_COMMIT_PIPELINE_ID"), } return web.RespondJson(ctx, w, data, http.StatusOK) diff --git a/cmd/web-app/handlers/routes.go b/cmd/web-app/handlers/routes.go index f14b91e..79a51fb 100644 --- a/cmd/web-app/handlers/routes.go +++ b/cmd/web-app/handlers/routes.go @@ -163,7 +163,6 @@ func APP(shutdown chan os.Signal, log *log.Logger, env webcontext.Env, staticDir check := Check{ MasterDB: masterDB, Redis: redis, - Renderer: renderer, } app.Handle("GET", "/v1/health", check.Health) diff --git a/tools/devops/cmd/cicd/service_build.go b/tools/devops/cmd/cicd/service_build.go index c090d79..adc67b5 100644 --- a/tools/devops/cmd/cicd/service_build.go +++ b/tools/devops/cmd/cicd/service_build.go @@ -199,6 +199,9 @@ func ServiceBuild(log *log.Logger, req *serviceBuildRequest) error { return errors.Wrapf(err, "Failed parse relative path for %s from %s", req.DockerFile, req.ProjectRoot) } + // Name of the first build stage declared in the docckerFile. + var buildStageName string + // When the dockerFile is multistage, caching can be applied. Scan the dockerFile for the first stage. // FROM golang:1.12.6-alpine3.9 AS build_base var buildBaseImageTag string @@ -213,9 +216,6 @@ func ServiceBuild(log *log.Logger, req *serviceBuildRequest) error { // any changes to the lines associated with the first stage force cache to be reset. var stageLines []string - // Name of the first build stage declared in the docckerFile. - var buildStageName string - // Loop through all the lines in the Dockerfile searching for the lines associated with the first build stage. scanner := bufio.NewScanner(file) for scanner.Scan() { @@ -299,7 +299,7 @@ func ServiceBuild(log *log.Logger, req *serviceBuildRequest) error { "--build-arg", "service=" + req.ServiceName, "--build-arg", "env=" + req.Env, "-t", buildBaseImageTag, - "--target", "build_base", + "--target", buildStageName, ".", })