Skip to content

Commit

Permalink
🌱 add lint, workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
anngdinh committed Mar 21, 2024
1 parent d545cc9 commit 24a166c
Show file tree
Hide file tree
Showing 13 changed files with 211 additions and 16 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Create and publish a Docker image

on:
release:
types: [published]

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
16 changes: 16 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Docker Image CI

on:
push:
branches: [ "main", "dev" ]

jobs:

build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Build the Docker image
run: docker build . --file Dockerfile --tag my-image-name:$(date +%s)
22 changes: 22 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# golangci-lint run
name: golangci-lint
on:
push:
branches:
- dev
- main

jobs:
golangci:
name: lint-codebase
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: "1.20"
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.52.2
args: --timeout 15m0s --verbose --out-${NO_FUTURE}format tab
19 changes: 19 additions & 0 deletions .github/workflows/govulncheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# govulncheck ./...
name: govulncheck
on:
push:
branches:
- "dev"
- "main"

jobs:
analyze:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- name: Scan for Vulnerabilities in Code
uses: golang/govulncheck-action@v1
with:
go-version-input: 1.21.8
go-package: ./...
64 changes: 64 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# go run github.com/golangci/golangci-lint/cmd/[email protected] run ./...
# golangci-lint run ./...
---
#################################
#################################
## Super Linter GitHub Actions ##
#################################
#################################
name: Lint Code Base

#
# Documentation:
# https://help.github.com/en/articles/workflow-syntax-for-github-actions
#

#############################
# Start the job on all push #
#############################
on:
push:
branches: ["dev", "main"]

###############
# Set the Job #
###############
permissions: {}

jobs:
build:
# Name the Job
permissions:
contents: read # to fetch code (actions/checkout)
statuses: write # to mark status of each linter run (github/super-linter)

name: Lint Code Base
# Set the agent to run on
runs-on: ubuntu-latest

##################
# Load all steps #
##################
steps:
##########################
# Checkout the code base #
##########################
- name: Checkout Code
uses: actions/checkout@v4
with:
# Full git history is needed to get a proper list of changed files within `super-linter`
fetch-depth: 0

################################
# Run Linter against code base #
################################
- name: Lint Code Base
uses: super-linter/[email protected]
env:
VALIDATE_ALL_CODEBASE: false
DEFAULT_BRANCH: dev
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LINTER_RULES_PATH: "."
# MARKDOWN_CONFIG_FILE: .markdownlint.yml
VALIDATE_MARKDOWN: true
VALIDATE_BASH: true
26 changes: 26 additions & 0 deletions .github/workflows/readme-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Lint plugin readmes
on:
push:
branches:
- dev
- main

jobs:
run-readme-linter:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v5
with:
go-version: "1.21.8"
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v42
with:
base_sha: ${{ github.event.pull_request.base.sha }}
files: ./plugins/**/README.md
- name: Run readme linter on changed files
if: steps.changed-files.outputs.any_changed == 'true'
run: go run ./tools/readme_linter ${{ steps.changed-files.outputs.all_changed_files }}
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@
## BUILD ARGS ##
################################################################################
# This build arg allows the specification of a custom Golang image.
ARG GOLANG_IMAGE=quay.io/cuongdm8499/golang:1.21.5
ARG GOLANG_IMAGE=golang:1.21.5

# The distroless image on which the CPI manager image is built.
#
# Please do not use "latest". Explicit tags should be used to provide
# deterministic builds. Follow what kubernetes uses to build
# kube-controller-manager, for example for 1.27.x:
# https://github.com/kubernetes/kubernetes/blob/release-1.27/build/common.sh#L99
ARG DISTROLESS_IMAGE=quay.io/cuongdm8499/go-runner:v2.3.1-go1.21.5-bookworm.0
ARG DISTROLESS_IMAGE=registry.k8s.io/build-image/go-runner:v2.3.1-go1.21.5-bookworm.0

# We use Alpine as the source for default CA certificates and some output
# images
ARG ALPINE_IMAGE=quay.io/cuongdm8499/alpine:3.17.5
ARG ALPINE_IMAGE=alpine:3.17.5

# cinder-csi-plugin uses Debian as a base image
ARG DEBIAN_IMAGE=quay.io/cuongdm8499/debian-base:bullseye-v1.4.3
ARG DEBIAN_IMAGE=registry.k8s.io/build-image/debian-base:bullseye-v1.4.3

################################################################################
## BUILD STAGE ##
Expand Down Expand Up @@ -67,10 +67,10 @@ RUN make build GOOS=${TARGETOS} GOARCH=${TARGETARCH} GOPROXY=${GOPROXY} VERSION=
##
## vngcloud-controller-manager
##
FROM --platform=${TARGETPLATFORM} ${DISTROLESS_IMAGE} as vcontainer-ccm
FROM --platform=${TARGETPLATFORM} ${DISTROLESS_IMAGE} as vngcloud-controller-manager

COPY --from=certs /etc/ssl/certs /etc/ssl/certs
COPY --from=builder /build/vcontainer-ccm /bin/vcontainer-ccm
COPY --from=builder /build/vngcloud-controller-manager /bin/vngcloud-controller-manager

LABEL name="vngcloud-controller-manager" \
license="Apache Version 2.0" \
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
![dev-staging-env](https://badgen.net/badge/DEV-STAGING/environment/blue?icon=github)

## Build and push image

- For short, just run the following command:

```bash=
make clean && push-multiarch-images
```

- Quick build:

```bash=
make clean && make build && make bush-local-images
```
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ require (
google.golang.org/genproto/googleapis/api v0.0.0-20230726155614-23370e0ffb3e // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/grpc v1.58.3 // indirect
google.golang.org/protobuf v1.31.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func PatchService(ctx context.Context, client clientset.Interface, cur, mod *lCo

func IsPoolProtocolValid(pPool *lObjects.Pool, pPort lCoreV1.ServicePort, pPoolName string) bool {
if pPool != nil &&
lStr.ToUpper(lStr.TrimSpace(pPool.Protocol)) != lStr.ToUpper(lStr.TrimSpace(string(pPort.Protocol))) &&
lStr.EqualFold(lStr.TrimSpace(pPool.Protocol), lStr.TrimSpace(string(pPort.Protocol))) &&
pPoolName == pPool.Name {
return false
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/vngcloud/vcontainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"

"github.com/cuongpiger/joat/utils"
metadata2 "github.com/vngcloud/vngcloud-controller-manager/pkg/utils/metadata"
// metadata2 "github.com/vngcloud/vngcloud-controller-manager/pkg/utils/metadata"
vconSdkClient "github.com/vngcloud/vngcloud-go-sdk/client"
"github.com/vngcloud/vngcloud-go-sdk/vngcloud"
lK8sCore "k8s.io/api/core/v1"
Expand All @@ -20,7 +20,7 @@ type (
VContainer struct {
provider *vconSdkClient.ProviderClient
vLbOpts VLbOpts
metadataOpts metadata2.Opts
// metadataOpts metadata2.Opts
config *Config
extraInfo *ExtraInfo

Expand Down
10 changes: 5 additions & 5 deletions pkg/vngcloud/vlb.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ type (
preferredIPFamily lCoreV1.IPFamily // preferred (the first) IP family indicated in service's `spec.ipFamilies`
flavorID string
lbType lLoadBalancerV2.CreateOptsTypeOpt
projectID string
// projectID string
subnetID string
isOwner bool
// isOwner bool
allowedCIRDs string
idleTimeoutClient int
idleTimeoutMember int
Expand Down Expand Up @@ -234,12 +234,12 @@ func (s *vLB) ensureLoadBalancer(
return nil, lErrors.NewErrConflictServiceAndCloud("the loadbalancer type of the original loadbalancer and service file are not match")
}

createNewLb = false
// createNewLb = false
} else {
// User want you to create a new loadbalancer for this service
klog.V(5).Infof("did not specify load balancer ID, maybe creating a new one")
isOwner = true
createNewLb = true
// isOwner = true
// createNewLb = true
}

// If until this step, can not find any load balancer for this cluster, find entire the project
Expand Down

0 comments on commit 24a166c

Please sign in to comment.