Skip to content

Commit

Permalink
Merge pull request #2 from navidshariaty/main
Browse files Browse the repository at this point in the history
add ENVIRONMENT env and modify deployment
  • Loading branch information
navidshariaty authored Jun 26, 2023
2 parents 04eccee + de54387 commit 6289b44
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 24 deletions.
45 changes: 33 additions & 12 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
8 changes: 7 additions & 1 deletion cmd/server.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"fmt"
"os"

"github.com/snapp-incubator/snappcloud-status-backend/internal/api/http"
Expand Down Expand Up @@ -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())
Expand Down
5 changes: 5 additions & 0 deletions deployments/server/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 6 additions & 11 deletions internal/config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 6289b44

Please sign in to comment.