diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a977e24..1aee4da 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -3,10 +3,22 @@ name: ci on: push: - tags: - - '**' + branches: [ main ] + tags: [ '**' ] + pull_request: + branches: [ main ] jobs: + lint: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + version: latest + args: --timeout 5m test: name: test runs-on: ubuntu-latest @@ -22,23 +34,32 @@ jobs: build: name: build runs-on: ubuntu-latest - permissions: - packages: write needs: + - lint - test steps: - - uses: actions/checkout@v3 - - uses: docker/setup-buildx-action@v2 - - uses: docker/setup-qemu-action@v2 - - uses: docker/login-action@v2 + - uses: actions/checkout@v2 + - uses: docker/setup-qemu-action@v1 + - uses: docker/setup-buildx-action@v1 + - uses: docker/login-action@v1 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - - uses: docker/build-push-action@v4 + - uses: docker/metadata-action@v3 + id: meta with: + images: ghcr.io/${{ github.repository }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + - uses: docker/build-push-action@v2 + with: + file: "Dockerfile" context: . + platforms: linux/amd64 push: true - tags: | - ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ github.ref_name }} - ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/cmd/server.go b/cmd/server.go index 4948ae2..5b33f44 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -1,6 +1,7 @@ package cmd import ( + "fmt" "os" "github.com/snapp-incubator/snappcloud-status-backend/internal/api/http" @@ -32,7 +33,12 @@ func (cmd *Server) main(cfg *config.Config, trap chan os.Signal) { go querierObj.Start() server := http.New(loggerObj, querierObj) - go server.Serve(8080) + go func() { + err := server.Serve(8080) + if err != nil { + panic(fmt.Errorf("error on Serve function: %s", err)) + } + }() // Keep this at the bottom of the main function field := zap.String("signal trap", (<-trap).String()) diff --git a/deployments/server/templates/deployment.yaml b/deployments/server/templates/deployment.yaml index 830a21b..eb6e145 100644 --- a/deployments/server/templates/deployment.yaml +++ b/deployments/server/templates/deployment.yaml @@ -39,6 +39,11 @@ spec: - name: http containerPort: {{ .Values.service.port }} protocol: {{ .Values.service.protocol }} + env: + - name: ENVIRONMENT + value: Production + - name: GIN_MODE + value: release livenessProbe: httpGet: path: /healthz/liveness diff --git a/internal/config/load.go b/internal/config/load.go index 58af2e4..9f2e953 100644 --- a/internal/config/load.go +++ b/internal/config/load.go @@ -10,16 +10,15 @@ import ( "github.com/knadh/koanf/parsers/yaml" "github.com/knadh/koanf/providers/rawbytes" "github.com/knadh/koanf/v2" - "k8s.io/client-go/rest" ) const ( - delimiter = "." - - tagName = "koanf" - + delimiter = "." + tagName = "koanf" upTemplate = "================ Loaded Configuration ================" bottomTemplate = "======================================================" + productionEnv = "Production" + stagingEnv = "Staging" ) func Load(print bool) *Config { @@ -61,12 +60,8 @@ func LoadValues(k *koanf.Koanf) error { } func loadConfigmap(k *koanf.Koanf) error { - // this is a hack to check whether we are in cluster or not - if _, err := rest.InClusterConfig(); err != nil { - if err == rest.ErrNotInCluster { - return nil - } - panic(fmt.Errorf("error creating Kubernetes config: \n%v", err)) + if os.Getenv("ENVIRONMENT") != productionEnv { + return nil } cm, err := os.ReadFile("/etc/snappcloud-status-backend/configs.yml")