Skip to content

Commit

Permalink
init v1
Browse files Browse the repository at this point in the history
  • Loading branch information
genos1998 committed Jul 16, 2024
1 parent c8e804d commit 26633f4
Show file tree
Hide file tree
Showing 49 changed files with 52,032 additions and 0 deletions.
61 changes: 61 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#
# Copyright 2021 OpsMx, Inc.
#
# 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.
#

#
# Install the latest versions of our mods. This is done as a separate step
# so it will pull from an image cache if possible, unless there are changes.
#

FROM --platform=linux/amd64 golang:alpine AS buildmod
RUN mkdir /build
WORKDIR /build
COPY go.mod .
COPY go.sum .
RUN go mod download

#
# Compile the code.
#
FROM buildmod AS build-binaries
COPY . .
ARG GIT_BRANCH
ARG GIT_HASH
ARG BUILD_TYPE
ARG TARGETOS
ARG TARGETARCH
ENV GIT_BRANCH=${GIT_BRANCH} GIT_HASH=${GIT_HASH} BUILD_TYPE=${BUILD_TYPE} CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH}
RUN mkdir /out
RUN go build -o /out/upgrade-script -ldflags="-X 'github.com/OpsMx/go-app-base/version.buildType=${BUILD_TYPE}' -X 'github.com/OpsMx/go-app-base/version.gitHash=${GIT_HASH}' -X 'github.com/OpsMx/go-app-base/version.gitBranch=${GIT_BRANCH}'" .

#
# Establish a base OS image used by all the applications.
#
FROM alpine:3 AS base-image
RUN apk update \
&& apk upgrade \
&& apk add ca-certificates curl jq bash git \
&& rm -rf /var/cache/apk/*
WORKDIR /app
COPY docker/run.sh /app/run.sh
ENTRYPOINT ["/bin/sh", "/app/run.sh"]

#
# Build the Upgrade-Script image. This should be a --target on docker build.
#
FROM base-image AS upgrade-script-image
COPY --from=build-binaries /out/upgrade-script /app
CMD ["/app/upgrade-script"]

105 changes: 105 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#
# Copyright 2021-2022 OpsMx, Inc.
#
# 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.
#

TARGETS=test local
PLATFORM=linux/amd64,linux/arm64
BUILDX=docker buildx build --pull --platform ${PLATFORM}
IMAGE_PREFIX=docker.flame.org/library/

#
# Build targets. Adding to these will cause magic to occur.
#

# These are the targets for Docker images.
# Dockerfiles should have a target that ends in -image
IMAGE_TARGETS = upgrade-script

#
# Below here lies magic...
#

all_deps := $(shell find * -name '*.go' | grep -v _test)

now := $(shell date -u +%Y%m%dT%H%M%S)

#
# Default target.
#

.PHONY: all
all: ${TARGETS}

#
# make a buildtime directory to hold the build timestamp files
#
buildtime:
[ ! -d buildtime ] && mkdir buildtime

#
# set git info details
#
set-git-info:
@$(eval GIT_BRANCH=$(shell git describe --tags))
@$(eval GIT_HASH=$(shell git rev-parse ${GIT_BRANCH}))


#
# Multi-architecture image builds
#
.PHONY: images
images: buildtime clean-image-names set-git-info $(addsuffix .tstamp, $(addprefix buildtime/,$(IMAGE_TARGETS)))

buildtime/%.tstamp:: ${all_deps} Dockerfile
${BUILDX} \
--tag ${IMAGE_PREFIX}$(patsubst %.tstamp,%,$(@F)):latest \
--tag ${IMAGE_PREFIX}$(patsubst %.tstamp,%,$(@F)):${GIT_BRANCH} \
--target $(patsubst %.tstamp,%,$(@F))-image \
--build-arg GIT_HASH=${GIT_HASH} \
--build-arg GIT_BRANCH=${GIT_BRANCH} \
--build-arg BUILD_TYPE=release \
-f Dockerfile \
--push .
echo >> buildtime/image-names.txt ${IMAGE_PREFIX}$(patsubst %.tstamp,%,$(@F)):latest
echo >> buildtime/image-names.txt ${IMAGE_PREFIX}$(patsubst %.tstamp,%,$(@F)):${GIT_BRANCH}
@touch $@

.PHONY: image-names
image-names:
[ -n "${GITHUB_OUTPUT}" ] && echo imageNames=$(shell echo `cat buildtime/image-names.txt` | sed 's/\ /,\ /g') >> ${GITHUB_OUTPUT}

#
# Test targets
#

.PHONY: test
test:
go test -race ./...

#
# Clean the world.
#

.PHONY: clean
clean: clean-image-names
rm -f buildtime/*.tstamp
rm -f bin/*

.PHONY: really-clean
really-clean: clean

.PHONY: clean-image-names
clean-image-names:
rm -f buildtime/image-names.txt
50 changes: 50 additions & 0 deletions april2024june2024/appLevelTools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package april2024june2024

import (
"context"
"fmt"
"upgradationScript/april2024june2024/june2024"

"upgradationScript/logger"

"github.com/Khan/genqlient/graphql"
)

func populateAppLevelTools(prodDgraphClient graphql.Client) error {
ctx := context.Background()

logger.Logger.Debug("--------------Populating App Env Tools Data transition-----------------")

appEnvs, err := june2024.AppEnvTools(ctx, prodDgraphClient)
if err != nil {
return fmt.Errorf("populateAppLevelTools: could'nt query RunhistoriesData error: %s", err.Error())
}

for _, appEnv := range appEnvs.QueryApplicationEnvironment {
logger.Logger.Debug("---------------------------------------------")
logger.Sl.Debugf("App Env Tools to be populated for id %v", appEnv.Id)

tools := []string{}

for _, deployment := range appEnv.Deployments {
logger.Sl.Debugf("Gathering Tools used in policy checks for deployment id %v", deployment.Id)
for _, runHistory := range deployment.PolicyRunHistory {
logger.Sl.Debugf("Tool used in policy run history id: %v is %v", runHistory.Id, runHistory.DatasourceTool)
tools = AppendIfNotPresent(tools, runHistory.DatasourceTool)
}
}

logger.Sl.Debugf("App Env Tools to be populated with tools %v for id %v", tools, appEnv.Id)

if _, err := june2024.UpdateApplicationEnvironmentWithTools(ctx, prodDgraphClient, appEnv.Id, tools); err != nil {
return fmt.Errorf("populateAppLevelTools: UpdateApplicationEnvironmentWithTools error: %s", err.Error())
}

logger.Sl.Debugf("added tools for AppEnv Id %v successfully", appEnv.Id)
logger.Logger.Debug("---------------------------------------------")
}

logger.Logger.Debug("--------------Completed App Env Tools Data transition-----------------")

return nil
}
17 changes: 17 additions & 0 deletions april2024june2024/april2024/genqlient.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
schema: schema.graphql
operations:
- queries.graphql
generated: schema-generated.go
package: april2024
use_struct_references: true
bindings:
Boolean:
type: "*bool"
DateTime:
type: "*time.Time"
Int64:
type: int64
Int:
type: "*int"
ID:
type: "*string"
16 changes: 16 additions & 0 deletions april2024june2024/april2024/queries.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
query QueryRunHistory {
queryRunHistory(order: { asc: CreatedAt }, filter: { Pass: false }) {
id
AlertTitle
AlertMessage
Suggestions
Error
Severity
CreatedAt
UpdatedAt
Action
JiraUrl
Status
Reason
}
}
126 changes: 126 additions & 0 deletions april2024june2024/april2024/schema-generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 26633f4

Please sign in to comment.