Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
Signed-off-by: Takeshi Yoshimura <tyos@jp.ibm.com>
  • Loading branch information
takeshi-yoshimura committed Nov 22, 2023
0 parents commit a75f112
Show file tree
Hide file tree
Showing 91 changed files with 9,069 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
# Ignore build and test binaries.
bin/
testbin/
171 changes: 171 additions & 0 deletions .github/workflows/build_push_controller.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
name: Build and push images

on:
push:
branches:
- master
paths:
- api/**
- cmd/**
- controllers/**
- ./main.go
- ./go.mod
- ./go.sum
- config/**
- ./Dockerfile
- ./Makefile
workflow_dispatch:

env:
VERSION: '0.0.1'
IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }}

jobs:
build-push-bundle:
runs-on: ubuntu-latest
needs: build-push-controller
env:
IMAGE_NAME: ghcr.io/foundation-model-stack/ocp-efa-operator
BUNDLE_IMAGE_NAME: ghcr.io/foundation-model-stack/ocp-efa-operator-bundle
CHANNELS: stable
DEFAULT_CHANNEL: stable
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '1.19.2'
- name: set ARCH and OD
run: |
echo "ARCH=$(case $(uname -m) in x86_64) echo -n amd64 ;; aarch64) echo -n arm64 ;; *) echo -n $(uname -m) ;; esac)" >> $GITHUB_ENV
echo "OS=$(uname | awk '{print tolower($0)}')" >> $GITHUB_ENV
echo "OPERATOR_SDK_DL_URL=https://github.com/operator-framework/operator-sdk/releases/download/v1.23.0" >> $GITHUB_ENV
- name: download operator-sdk
run: curl -LO ${{ env.OPERATOR_SDK_DL_URL }}/operator-sdk_${{ env.OS }}_${{ env.ARCH }}
- name: move operator-sdk to binary path
run: chmod +x operator-sdk_${{ env.OS }}_${{ env.ARCH }} && sudo mv operator-sdk_${{ env.OS }}_${{ env.ARCH }} /usr/local/bin/operator-sdk
- name: Tidy
run: |
go mod tidy
- name: Make bundle
run: make bundle IMG=${{ env.IMAGE_NAME }}:v${{ env.VERSION }}
- name: Set up Docker
uses: docker/setup-buildx-action@v1
- name: Login to Docker
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ secrets.GH_USERNAME }}
password: ${{ secrets.GH_TOKEN }}
- name: Build and push bundle
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: |
${{ env.BUNDLE_IMAGE_NAME }}:latest
${{ env.BUNDLE_IMAGE_NAME }}:v${{ env.VERSION }}
file: ./bundle.Dockerfile

build-push-controller:
runs-on: ubuntu-latest
env:
IMAGE_NAME: ghcr.io/foundation-model-stack/ocp-efa-operator
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '1.21'
- name: Tidy
run: |
go mod tidy
make generate fmt vet
- name: Set up Docker
uses: docker/setup-buildx-action@v1
- name: Login to Docker
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ secrets.GH_USERNAME }}
password: ${{ secrets.GH_TOKEN }}
- name: Build and push controller
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: |
${{ env.IMAGE_NAME }}:${{ github.sha }}-${{ github.run_number }}
${{ env.IMAGE_NAME }}:latest
${{ env.IMAGE_NAME }}:v${{ env.VERSION }}
file: ./Dockerfile

build-push-efa-dp:
runs-on: ubuntu-latest
env:
IMAGE_NAME: ghcr.io/foundation-model-stack/ocp-efa-device-plugin
CGO_ENABLED: 0
GOOS: linux
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '1.21'
- name: Tidy
run: |
go mod tidy
- name: Set up Docker
uses: docker/setup-buildx-action@v1
- name: Login to Docker
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ secrets.GH_USERNAME }}
password: ${{ secrets.GH_TOKEN }}
- name: Build
run: |
go build -v -a -ldflags '-extldflags "-static"' -gcflags="all=-N -l" -o ./bin/ocp-efa-device-plugin ./cmd/ocp-efa-device-plugin/
- name: Build and push controller
uses: docker/build-push-action@v2
with:
context: ./bin/
push: true
tags: |
${{ env.IMAGE_NAME }}:${{ github.sha }}-${{ github.run_number }}
${{ env.IMAGE_NAME }}:latest
${{ env.IMAGE_NAME }}:v${{ env.VERSION }}
file: ./cmd/ocp-efa-device-plugin/Dockerfile

build-push-gdrdrv-dp:
runs-on: ubuntu-latest
env:
IMAGE_NAME: ghcr.io/foundation-model-stack/ocp-gdrdrv-device-plugin
CGO_ENABLED: 0
GOOS: linux
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '1.21'
- name: Tidy
run: |
go mod tidy
- name: Set up Docker
uses: docker/setup-buildx-action@v1
- name: Login to Docker
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ secrets.GH_USERNAME }}
password: ${{ secrets.GH_TOKEN }}
- name: Build
run: |
go build -v -a -ldflags '-extldflags "-static"' -gcflags="all=-N -l" -o ./bin/ocp-gdrdrv-device-plugin ./cmd/ocp-gdrdrv-device-plugin/
- name: Build and push controller
uses: docker/build-push-action@v2
with:
context: ./bin/
push: true
tags: |
${{ env.IMAGE_NAME }}:${{ github.sha }}-${{ github.run_number }}
${{ env.IMAGE_NAME }}:latest
${{ env.IMAGE_NAME }}:v${{ env.VERSION }}
file: ./cmd/ocp-gdrdrv-device-plugin/Dockerfile
56 changes: 56 additions & 0 deletions .github/workflows/unittest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Perform unittest

on:
pull_request:
push:

jobs:
operator-test:
env:
CLUSTER_ID: default
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '1.21'
- name: set ARCH and OD
run: |
echo "ARCH=$(case $(uname -m) in x86_64) echo -n amd64 ;; aarch64) echo -n arm64 ;; *) echo -n $(uname -m) ;; esac)" >> $GITHUB_ENV
echo "OS=$(uname | awk '{print tolower($0)}')" >> $GITHUB_ENV
echo "OPERATOR_SDK_DL_URL=https://github.com/operator-framework/operator-sdk/releases/download/v1.23.0" >> $GITHUB_ENV
- name: download operator-sdk
run: curl -LO ${{ env.OPERATOR_SDK_DL_URL }}/operator-sdk_${{ env.OS }}_${{ env.ARCH }}
- name: move operator-sdk to binary path
run: chmod +x operator-sdk_${{ env.OS }}_${{ env.ARCH }} && sudo mv operator-sdk_${{ env.OS }}_${{ env.ARCH }} /usr/local/bin/operator-sdk
- name: Tidy
run: |
go mod tidy
- name: Make bundle
run: make bundle
- name: Test Controller
run: make operator-test
- name: Archive code coverage results
uses: actions/upload-artifact@v3
with:
name: code-coverage-report
path: operator-cover.html
device-plugin-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '1.21'
- name: Tidy
run: |
go mod tidy
- name: Make generate
run: make generate
- name: Test Uploader
run: make dp-test
- name: Archive code coverage results
uses: actions/upload-artifact@v3
with:
name: code-coverage-report
path: dp-cover.html
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
bin
testbin/*
Dockerfile.cross

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
*.html

# Kubernetes Generated files - skip generated files, except for vendored files

!vendor/**/zz_generated.*

# editor and IDE paraphernalia
.idea
*.swp
*.swo
*~
33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Build the manager binary
FROM golang:1.21 as builder
ARG TARGETOS
ARG TARGETARCH

WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download

# Copy the go source
COPY main.go main.go
COPY api/ api/
COPY controllers/ controllers/

# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/manager .
USER 65532:65532

ENTRYPOINT ["/manager"]
Loading

0 comments on commit a75f112

Please sign in to comment.