Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor/
Empty file added .gitkeep
Empty file.
1 change: 0 additions & 1 deletion 1

This file was deleted.

43 changes: 43 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.20.4-alpine@sha256:0a03b591c358a0bb02e39b93c30e955358dadd18dc507087a3b7f3912c17fe13 as builder
RUN apk add --no-cache ca-certificates git
RUN apk add build-base
WORKDIR /src

# restore dependencies
COPY go.mod go.sum ./
RUN go mod download
COPY . .

# Skaffold passes in debug-oriented compiler flags
ARG SKAFFOLD_GO_GCFLAGS
RUN go build -gcflags="${SKAFFOLD_GO_GCFLAGS}" -o /go/bin/frontend .

FROM alpine:3.18.0@sha256:02bb6f428431fbc2809c5d1b41eab5a68350194fb508869a33cb1af4444c9b11 as release
RUN apk add --no-cache ca-certificates \
busybox-extras net-tools bind-tools
WORKDIR /src
COPY --from=builder /go/bin/frontend /src/server
COPY ./templates ./templates
COPY ./static ./static

# Definition of this variable is used by 'skaffold debug' to identify a golang binary.
# Default behavior - a failure prints a stack trace for the current goroutine.
# See https://golang.org/pkg/runtime/
ENV GOTRACEBACK=single

EXPOSE 8080
ENTRYPOINT ["/src/server"]
25 changes: 25 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
pipeline {
agent any

stages {
stage('Build & Tag Docker Image') {
steps {
script {
withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') {
sh "docker build -t abhishek0768/frontend:latest ."
}
}
}
}

stage('Push Docker Image') {
steps {
script {
withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') {
sh "docker push abhishek0768/frontend:latest"
}
}
}
}
}
}
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frontend

Run the following command to restore dependencies to `vendor/` directory:

dep ensure --vendor-only
64 changes: 64 additions & 0 deletions deployment_details.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package main

import (
"net/http"
"os"
"time"

"cloud.google.com/go/compute/metadata"
"github.com/sirupsen/logrus"
)

var deploymentDetailsMap map[string]string
var log *logrus.Logger

func init() {
initializeLogger()
// Use a goroutine to ensure loadDeploymentDetails()'s GCP API
// calls don't block non-GCP deployments. See issue #685.
go loadDeploymentDetails()
}

func initializeLogger() {
log = logrus.New()
log.Level = logrus.DebugLevel
log.Formatter = &logrus.JSONFormatter{
FieldMap: logrus.FieldMap{
logrus.FieldKeyTime: "timestamp",
logrus.FieldKeyLevel: "severity",
logrus.FieldKeyMsg: "message",
},
TimestampFormat: time.RFC3339Nano,
}
log.Out = os.Stdout
}

func loadDeploymentDetails() {
deploymentDetailsMap = make(map[string]string)
var metaServerClient = metadata.NewClient(&http.Client{})

podHostname, err := os.Hostname()
if err != nil {
log.Error("Failed to fetch the hostname for the Pod", err)
}

podCluster, err := metaServerClient.InstanceAttributeValue("cluster-name")
if err != nil {
log.Error("Failed to fetch the name of the cluster in which the pod is running", err)
}

podZone, err := metaServerClient.Zone()
if err != nil {
log.Error("Failed to fetch the Zone of the node where the pod is scheduled", err)
}

deploymentDetailsMap["HOSTNAME"] = podHostname
deploymentDetailsMap["CLUSTERNAME"] = podCluster
deploymentDetailsMap["ZONE"] = podZone

log.WithFields(logrus.Fields{
"cluster": podCluster,
"zone": podZone,
"hostname": podHostname,
}).Debug("Loaded deployment details")
}
24 changes: 24 additions & 0 deletions genproto.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash -eu
#
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# [START gke_frontend_genproto]

PATH=$PATH:$GOPATH/bin
protodir=../../protos

protoc --go_out=plugins=grpc:genproto -I $protodir $protodir/demo.proto

# [END gke_frontend_genproto]
Loading