Restructured workflow added
Some checks failed
dev test / test (push) Failing after 8s
dev test / vulnCheck (push) Has been skipped
dev test / Ci-Lint (push) Has been skipped

This commit is contained in:
maximo tejeda 2024-12-03 22:09:27 -04:00
parent 40dceb78c8
commit 3888c47d17
17 changed files with 206 additions and 58 deletions

View File

@ -1,19 +0,0 @@
name: Gitea Actions Demo
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
on: [push]
jobs:
Explore-Gitea-Actions:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically and automagically triggered by a ${{ gitea.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!"
- run: echo "🔎 The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}."
- name: Check out repository code
uses: actions/checkout@v4
- run: echo "💡 The ${{ gitea.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ gitea.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."

106
.github/workflows/image_creation.yml vendored Normal file
View File

@ -0,0 +1,106 @@
name: ${{ github.actor }} executed Build Push Prod
on:
push:
tags:
- 'v[0-9]+\.[0-9]+\.[0-9]+'
jobs:
build:
runs-on: ubuntu-latest
env:
TOKEN: ${{ secrets.TOKEN }}
USERNAME: ${{ vars.USERNAME }}
TAG_VERSION: ${{ github.ref_name }}
steps:
- name: echo repo dir
id: repo-url
run: |
echo "repourl=$(echo ${{ github.server_url }} | sed -e 's;https://;;')" >> $GITHUB_OUTPUT
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Quemu
uses: docker/setup-qemu-action@v3
- name: Set Up BuildX
uses: docker/setup-buildx-action@v3
- name: Login to Docker
uses: docker/login-action@v3
with:
registry: https://git.maximotejeda.com
username: ${{ vars.USERNAME }}
password: ${{ secrets.PWD }}
- name: calculate short sha
id: calculate-sha
run: |
echo "shortsha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: "${{ steps.repo-url.outputs.repourl }}/${{ github.repository }}:${{ github.ref_name }}"
build-args: |
version=${{ github.ref_name }}
SHORTSHA=${{ steps.calculate-sha.outputs.shortsha }}
deploy:
runs-on: ubuntu-latest
needs: build
env:
TOKEN: ${{ secrets.TOKEN }}
TAG: ${{ github.ref_name }}
PASSWORD: $PWD
USERNAME: ${{ vars.USERNAME }}
TAG_VERSION: ${{ github.ref_name }}
NATS_SERVICE_URL: "${{ vars.NATS_SERVICE_URL }}"
ENV: "{{ vars.ENV }}"
APPLICATION_PORT: "${{ vars.APPLICATION_PORT }}"
APPLICATION_HOST: "${{ vars.APPLICATION_HOST }}"
DOLLAR_SERVICE_URL: "${{ vars.DOLLAR_SERVICE_URL }}"
steps:
- name: echo repo dir
id: repo-url
run: |
echo "repourl=$(echo ${{ github.server_url }} | sed -e 's;https://;;')" >> $GITHUB_OUTPUT
echo "repoName=$(echo ${{ github.repository }} | sed -e 's;${{ github.actor }}/;;')" >> $GITHUB_OUTPUT
echo "${{ github.repository }} | sed -e 's;${{ github.actor }}/;;')"
- name: Checkout code
uses: actions/checkout@v4
- name: install envsubst
run: |
apt update
apt install -y gettext-base
apt clean
- name: create deployment files
env:
IMAGE: "${{ steps.repo-url.outputs.repourl }}/${{ github.repository }}:${{ github.ref_name }}"
REPONAME: "${{ steps.repo-url.outputs.repoName }}"
run: |
envsubst < k8s/deployment.yml.template > k8s/deployment.yml
- name: Download kubectl
run: curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
- name: install kubectl
run: sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
- name: insert kube config
run: |
mkdir ~/.kube
export IMAGE="$( echo ${{ github.server_url }} | sed -e 's;https://;;')/${{ github.repository }}:${{ github.ref_name }}"
echo "${{ secrets.KUBECONFIG }}" > ~/.kube/config
- name: check pod
run: kubectl apply -f k8s/deployment.yml
- name: scale down deployment
continue-on-error: true
run: kubectl scale deployment ${{ steps.repo-url.outputs.repoName }} --replicas=0
- name: scale up deployment
run: kubectl scale deployment ${{ steps.repo-url.outputs.repoName }} --replicas=1

68
.github/workflows/test_project.yml vendored Normal file
View File

@ -0,0 +1,68 @@
name: "dev test"
on:
push:
branches:
- master
- dev
- 'feature/**'
paths:
- '**.go'
- '**.yml'
- '**.yaml'
jobs:
test:
runs-on: ubuntu-latest
env:
TOKEN: ${{ secrets.TOKEN }}
USERNAME: ${{ vars.USERNAME }}
TAG_VERSION: ${{ github.ref_name }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: run tidy
run: |
go mod tidy
- name: test with go
run: go test -v ./...
vulnCheck:
runs-on: ubuntu-latest
needs: test
env:
TOKEN: ${{ secrets.TOKEN }}
USERNAME: ${{ vars.USERNAME }}
TAG_VERSION: ${{ github.ref_name }}
steps:
- name: checkout Code
uses: actions/checkout@v4
- name: go vuln check
uses: golang/govulncheck-action@v1
with:
go-version-file: 'go.mod'
go-package: ./...
Ci-Lint:
runs-on: ubuntu-latest
needs: vulnCheck
env:
TOKEN: ${{ secrets.TOKEN }}
USERNAME: ${{ vars.USERNAME }}
TAG_VERSION: ${{ github.ref_name }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: CI lint Check
uses: golangci/golangci-lint-action@v6
with:
only-new-issues: true

View File

@ -38,7 +38,7 @@ run-local:clean build
@bin/$(BINAME) @bin/$(BINAME)
build: build:
@mkdir dolardb || true # @mkdir dolardb || true
@env GOOS=$(OS) GOARCH=$(arch) go build -o ./bin/$(BINAME) ./cmd/api/. @env GOOS=$(OS) GOARCH=$(arch) go build -o ./bin/$(BINAME) ./cmd/api/.
@env GOOS=$(OS) GOARCH=arm64 go build -o ./bin/$(BINAMEARM) ./cmd/api/. @env GOOS=$(OS) GOARCH=arm64 go build -o ./bin/$(BINAMEARM) ./cmd/api/.

View File

@ -8,10 +8,10 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"git.maximotejeda.com/maximo/us-dop-api/adapters/dolar" "git.maximotejeda.com/maximo/us-dop-api/internal/adapters/dolar"
"git.maximotejeda.com/maximo/us-dop-api/config" "git.maximotejeda.com/maximo/us-dop-api/config"
"git.maximotejeda.com/maximo/us-dop-api/handlers" "git.maximotejeda.com/maximo/us-dop-api/internal/handlers"
"git.maximotejeda.com/maximo/us-dop-api/middlewares" "git.maximotejeda.com/maximo/us-dop-api/internal/middlewares"
"git.maximotejeda.com/maximo/us-dop-api/static" "git.maximotejeda.com/maximo/us-dop-api/static"
"google.golang.org/grpc" "google.golang.org/grpc"

View File

@ -5,7 +5,7 @@ import (
"time" "time"
"git.maximotejeda.com/maximo/dolar/proto/golang/dolar" "git.maximotejeda.com/maximo/dolar/proto/golang/dolar"
"git.maximotejeda.com/maximo/us-dop-api/domain" "git.maximotejeda.com/maximo/us-dop-api/internal/domain"
"google.golang.org/grpc" "google.golang.org/grpc"
) )

View File

@ -6,8 +6,8 @@ import (
"net/http" "net/http"
"time" "time"
"git.maximotejeda.com/maximo/us-dop-api/domain" "git.maximotejeda.com/maximo/us-dop-api/internal/domain"
"git.maximotejeda.com/maximo/us-dop-api/ports" "git.maximotejeda.com/maximo/us-dop-api/internal/ports"
) )

View File

@ -9,8 +9,8 @@ import (
"strings" "strings"
"time" "time"
"git.maximotejeda.com/maximo/us-dop-api/domain" "git.maximotejeda.com/maximo/us-dop-api/internal/domain"
"git.maximotejeda.com/maximo/us-dop-api/helpers" "git.maximotejeda.com/maximo/us-dop-api/internal/helpers"
) )
// handler to parse query to the api // handler to parse query to the api

View File

@ -7,8 +7,8 @@ import (
"strings" "strings"
"time" "time"
"git.maximotejeda.com/maximo/us-dop-api/handlers/api" "git.maximotejeda.com/maximo/us-dop-api/internal/handlers/api"
"git.maximotejeda.com/maximo/us-dop-api/ports" "git.maximotejeda.com/maximo/us-dop-api/internal/ports"
) )
var ( var (

View File

@ -1,6 +1,6 @@
package ports package ports
import "git.maximotejeda.com/maximo/us-dop-api/domain" import "git.maximotejeda.com/maximo/us-dop-api/internal/domain"
type DolarService interface { type DolarService interface {
GetLatest(name string) (*domain.History, error) GetLatest(name string) (*domain.History, error)

View File

@ -1,51 +1,44 @@
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
name: us-dop-api name: $REPONAME
labels: labels:
app: us-dop-api app: $REPONAME
spec: spec:
replicas: 1 replicas: 1
selector: selector:
matchLabels: matchLabels:
app: us-dop-api app: $REPONAME
template: template:
metadata: metadata:
labels: labels:
app: us-dop-api app: $REPONAME
name: us-dop-api name: $REPONAME
spec: spec:
containers: containers:
- name: us-dop-pi - name: $REPONAME
image: localhost:32000/us-dop-api:latest image: $IMAGE
env: env:
- name: DOLLAR_SERVICE_URL - name: DOLLAR_SERVICE_URL
value: "dolar-grpc-svc:80" value: "$DOLLAR_SERVICE_URL"
- name: HOST - name: HOST
value: "0.0.0.0" value: "$HOST"
- name: NATSURI - name: NATSURI
value: "nats://nats-svc:4222" value: "$NATS_SERVICE_URL"
- name: PORT - name: PORT
value: "8080" value: "$PORT"
volumeMounts:
- name: database
mountPath: /app/dolardb
volumes:
- name: database
persistentVolumeClaim:
claimName: bank-crawler-pvc
--- ---
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
metadata: metadata:
name: us-dop-api-svc name: $REPONAME-svc
spec: spec:
type: LoadBalancer type: LoadBalancer
selector: selector:
app: us-dop-api app: $REPONAME
ports: ports:
- port: 80 - port: 80
targetPort: 8080 targetPort: $PORT
name: frontend name: frontend
--- ---
apiVersion: networking.k8s.io/v1 apiVersion: networking.k8s.io/v1
@ -54,7 +47,7 @@ metadata:
annotations: annotations:
# add an annotation indicating the issuer to use. # add an annotation indicating the issuer to use.
cert-manager.io/cluster-issuer: letsencrypt cert-manager.io/cluster-issuer: letsencrypt
name: us-dop-api-ingress name: $REPONAME-ingress
spec: spec:
rules: rules:
- host: cambio.maximotejeda.com - host: cambio.maximotejeda.com
@ -64,10 +57,10 @@ spec:
path: "/" path: "/"
backend: backend:
service: service:
name: us-dop-api-svc name: $REPONAME-svc
port: port:
number: 80 number: 80
tls: # < placing a host in the TLS config will determine what ends up in the cert's subjectAltNames #tls: # < placing a host in the TLS config will determine what ends up in the cert's subjectAltNames
- hosts: #- hosts:
- cambio.maximotejeda.com # - cambio.maximotejeda.com
secretName: cambio.maximotejeda-cert # < cert-manager will store the created certificate in this secret. # secretName: cambio.maximotejeda-cert # < cert-manager will store the created certificate in this secret.