Skip to content

Commit

Permalink
add cicd files for v2
Browse files Browse the repository at this point in the history
Signed-off-by: ImpSy <[email protected]>
  • Loading branch information
ImpSy committed Oct 17, 2024
1 parent 0165798 commit 7124a15
Show file tree
Hide file tree
Showing 5 changed files with 277 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* @Spotinst/team-bigdata
/.github/ @Spotinst/team-bigdata-devops
55 changes: 55 additions & 0 deletions .github/ocean-spark/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#
# Copyright 2017 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
#
# https://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.
#

ARG SPARK_IMAGE=spark:3.5.2

FROM golang:1.23.1 AS builder

WORKDIR /workspace

RUN --mount=type=cache,target=/go/pkg/mod/ \
--mount=type=bind,source=go.mod,target=go.mod \
--mount=type=bind,source=go.sum,target=go.sum \
go mod download

COPY . .
ENV GOCACHE=/root/.cache/go-build
ARG TARGETARCH

RUN --mount=type=cache,target=/go/pkg/mod/ \
--mount=type=cache,target="/root/.cache/go-build" \
CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} GO111MODULE=on make build-operator

FROM ${SPARK_IMAGE}

USER root

RUN yum install -y openssl \
&& yum clean all \
&& curl -fsSL "https://github.com/krallin/tini/releases/download/v0.19.0/tini-static-amd64" -o /sbin/tini \
&& chmod +x /sbin/tini

RUN mkdir -p /etc/k8s-webhook-server/serving-certs /home/spark && \
chmod -R g+rw /etc/k8s-webhook-server/serving-certs && \
chown -R 185 /etc/k8s-webhook-server/serving-certs /home/spark

USER 185

COPY --from=builder /workspace/bin/spark-operator /usr/bin/spark-operator

COPY entrypoint.sh /usr/bin/

ENTRYPOINT ["/usr/bin/entrypoint.sh"]
43 changes: 43 additions & 0 deletions .github/ocean-spark/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
REGISTRY ?=
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)

VERSION = $(shell git rev-parse --short=7 HEAD)
IMAGE_NAME = spark-operator
SPARK_BASE_IMAGE = public.ecr.aws/f4k1p1n4/spark:netapp-spark-support-image-v3.5-rel20240916
TAG = $(VERSION)
PLATFORM ?= amd64


build:
docker buildx build --load \
-t $(REGISTRY)$(IMAGE_NAME):$(TAG_RH)-$(PLATFORM) \
-f .github/ocean-spark/Dockerfile.rh \
--platform linux/$(PLATFORM) \
--build-arg SPARK_IMAGE=$(SPARK_BASE_IMAGE) .

push:
docker tag $(REGISTRY)$(IMAGE_NAME):$(TAG)-$(PLATFORM) $(REGISTRY)$(IMAGE_NAME):${BRANCH}-$(PLATFORM)
docker push $(REGISTRY)$(IMAGE_NAME):${BRANCH}-$(PLATFORM)
@if [ "$(BRANCH)" = "ocean-spark-v2" ]; then \
docker push $(REGISTRY)$(IMAGE_NAME):$(TAG)-$(PLATFORM); \
fi


push-manifest:
docker manifest create $(REGISTRY)$(IMAGE_NAME):${BRANCH} \
$(REGISTRY)$(IMAGE_NAME):${BRANCH}-amd64 \
$(REGISTRY)$(IMAGE_NAME):${BRANCH}-arm64
docker manifest push $(REGISTRY)$(IMAGE_NAME):${BRANCH}
@if [ "$(BRANCH)" == "ocean-spark-v2" ]; then \
docker manifest create $(REGISTRY)$(IMAGE_NAME):$(TAG) \
$(REGISTRY)$(IMAGE_NAME):$(TAG)-amd64 \
$(REGISTRY)$(IMAGE_NAME):$(TAG)-arm64; \
docker manifest push $(REGISTRY)$(IMAGE_NAME):$(TAG); \
fi

show:
@echo "Images available:"
@if [ "$(BRANCH)" = "ocean-spark-v2" ]; then \
echo "-> $(REGISTRY)$(IMAGE_NAME):$(TAG)"; \
fi
@echo "-> $(REGISTRY)$(IMAGE_NAME):${BRANCH}"
72 changes: 72 additions & 0 deletions .github/ocean-spark/actions/release/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: 'Release Action'
description: 'Build and Push the application docker image'

inputs:
aws-access-key-id:
description: 'AWS Access Key ID'
required: true
aws-secret-access-key:
description: 'AWS Secret Access Key'
required: true
public-registry-id:
description: 'Public ECR Registry ID'
required: true

runs:
using: "composite"
steps:
- name: Get branch names
id: branch-name
uses: tj-actions/branch-names@v5

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to Amazon ECR
uses: docker/login-action@v1
with:
registry: public.ecr.aws
username: ${{ inputs.aws-access-key-id }}
password: ${{ inputs.aws-secret-access-key }}

- name: Build AMD64 images
run: make -f .github/ocean-spark/Makefile build
shell: bash
env:
BRANCH: ${{ steps.branch-name.outputs.current_branch }}
REGISTRY: public.ecr.aws/${{ inputs.public-registry-id }}/
PLATFORM: amd64

- name: Push AMD64 images
run: make -f .github/ocean-spark/Makefile push
shell: bash
env:
BRANCH: ${{ steps.branch-name.outputs.current_branch }}
REGISTRY: public.ecr.aws/${{ inputs.public-registry-id }}/
PLATFORM: amd64

- name: Build ARM64 images
run: make -f .github/ocean-spark/Makefile build
shell: bash
env:
BRANCH: ${{ steps.branch-name.outputs.current_branch }}
REGISTRY: public.ecr.aws/${{ inputs.public-registry-id }}/
PLATFORM: arm64

- name: Push ARM64 images
run: make -f .github/ocean-spark/Makefile push
shell: bash
env:
BRANCH: ${{ steps.branch-name.outputs.current_branch }}
REGISTRY: public.ecr.aws/${{ inputs.public-registry-id }}/
PLATFORM: arm64

- name: Push manifest
run: make -f .github/ocean-spark/Makefile push-manifest
shell: bash
env:
BRANCH: ${{ steps.branch-name.outputs.current_branch }}
REGISTRY: public.ecr.aws/${{ inputs.public-registry-id }}/
105 changes: 105 additions & 0 deletions .github/workflows/cicd-ofas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: CICD
on:
push:
branches:
- ocean-spark-v2
pull_request:
branches:
- ocean-spark-v2

jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: Run go mod tidy
run: |
go mod tidy
if ! git diff --quiet; then
echo "Please run 'go mod tidy' and commit the changes."
git diff
false
fi
- name: Generate code
run: |
make generate
if ! git diff --quiet; then
echo "Need to re-run 'make generate' and commit the changes."
git diff
false
fi
- name: Run go fmt check
run: |
make go-fmt
if ! git diff --quiet; then
echo "Need to re-run 'make go-fmt' and commit the changes."
git diff
false
fi
- name: Run go vet check
run: |
make go-vet
if ! git diff --quiet; then
echo "Need to re-run 'make go-vet' and commit the changes."
git diff
false
fi
- name: Run golangci-lint
run: |
make go-lint
- name: Run unit tests
run: make unit-test

cd-dev-archi:
needs: [ci]
runs-on: ubuntu-latest
environment: dev

strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm64

steps:
- if: ${{ github.event_name != 'pull_request' }}
uses: actions/checkout@v4

- if: ${{ github.event_name == 'pull_request' }}
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: release to dev
uses: ./.github/ocean-spark/actions/release
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
public-registry-id: n8e8v3t5

cd-prod:
if: ${{ github.event_name != 'pull_request' }}
needs: [cd-dev]
runs-on: ubuntu-latest
environment: prod
steps:
- uses: actions/checkout@v4

- name: release to prod
uses: ./.github/ocean-spark/actions/release
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
public-registry-id: f4k1p1n4

0 comments on commit 7124a15

Please sign in to comment.