initialisation

This commit is contained in:
Nicolas CARON 2024-11-20 11:01:04 +01:00
parent febdae9479
commit c74114fe66
6 changed files with 169 additions and 0 deletions

View File

@ -0,0 +1,81 @@
name: Build and Push Docker Image
on:
push:
tags:
- '*'
branches:
- main
- dev
jobs:
build_and_push:
runs-on: ubuntu-latest
steps:
- name: Install Docker
run: |
apt-get update
apt-get install -y docker.io
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set Kubernetes Context
uses: azure/k8s-set-context@v4
with:
method: kubeconfig
kubeconfig: ${{secrets.buildx_kubeconfig}}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver: kubernetes
driver-opts: |
namespace=gitea
- name: Login to Docker Registry
uses: docker/login-action@v3
with:
registry: git.coopgo.io
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Extract metadata (tags, labels) for Docker image
id: metadata
uses: docker/metadata-action@v3
with:
images: git.coopgo.io/${{gitea.repository}}
tags: |
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
flavor: |
latest=auto
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ steps.metadata.outputs.tags }}
build-args: |
ACCESS_TOKEN_USR=${{gitea.actor}}
ACCESS_TOKEN_PWD=${{gitea.token}}
# BUILD WITH KANIKO
# - name: Kaniko build and push
# uses: aevea/action-kaniko@master
# with:
# build_file: Dockerfile
# registry: git.coopgo.io
# username: ${{secrets.registry_user}}
# password: ${{secrets.registry_token}}
# image: ${{gitea.repository}}
# tag: ${{gitea.ref_name}}
# cache: true
# cache_registry: git.coopgo.io/${{gitea.repository}}/cache
# extra-args: |
# ACCESS_TOKEN_USR=${{gitea.actor}}
# ACCESS_TOKEN_PWD=${{gitea.token}}

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
config.yaml
.vscode
.idea
__debug_bin

27
Dockerfile Normal file
View File

@ -0,0 +1,27 @@
FROM golang:alpine as builder
ARG ACCESS_TOKEN_USR="nothing"
ARG ACCESS_TOKEN_PWD="nothing"
RUN apk add --no-cache ca-certificates tzdata git
WORKDIR /
# Create a netrc file using the credentials specified using --build-arg
RUN printf "machine git.coopgo.io\n\
login ${ACCESS_TOKEN_USR}\n\
password ${ACCESS_TOKEN_PWD}\n"\
>> ~/.netrc
RUN chmod 600 ~/.netrc
COPY . .
RUN go mod download && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /server
FROM scratch
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=builder /server /
EXPOSE 8080
ENTRYPOINT ["/server"]

42
config.go Normal file
View File

@ -0,0 +1,42 @@
package main
import (
"strings"
"github.com/spf13/viper"
)
func ReadConfig() (*viper.Viper, error) {
defaults := map[string]any{
"name": "COOPGO Agenda",
"dev_env": false,
"storage": map[string]any{
"type": "mongodb",
"mongodb": map[string]any{
"host": "localhost",
"port": "27017",
"db_name": "coopgo_platform",
"collections": map[string]any{
"events": "diags",
},
},
},
"services": map[string]any{
"grpc": map[string]any{
"enable": true,
"port": 8098,
},
},
}
v := viper.New()
for key, value := range defaults {
v.SetDefault(key, value)
}
v.SetConfigName("config")
v.AddConfigPath(".")
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
v.AutomaticEnv()
err := v.ReadInConfig()
return v, err
}

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module git.coopgo.io/coopgo-platform/diags
go 1.18

12
main.go Normal file
View File

@ -0,0 +1,12 @@
package main
import (
"os"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"git.coopgo.io/coopgo-platform/diags/grpcapi"
"git.coopgo.io/coopgo-platform/diags/handlers"
"git.coopgo.io/coopgo-platform/diags/storage"
)