Compare commits
5 Commits
desarrollo
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 5d927d1261 | |||
| 563c4dec46 | |||
| 80f414e393 | |||
| 2f1757dc66 | |||
| ccca57eed4 |
25
.gitea/workflows/demo.yaml
Normal file
25
.gitea/workflows/demo.yaml
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
name: Deploy demo
|
||||||
|
run-name: ${{ gitea.actor }}
|
||||||
|
on: [push]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
Deploy:
|
||||||
|
runs-on: dagger
|
||||||
|
steps:
|
||||||
|
- name: Clone Devops Repo
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: main
|
||||||
|
repository: junior.bonilla/example_app
|
||||||
|
token: ${{ secrets.PIPELINEDEPLOY }}
|
||||||
|
path: devops
|
||||||
|
- name: Clone Code Repo
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
repository: junior.bonilla/example_app
|
||||||
|
token: ${{ secrets.PIPELINEDEPLOY }}
|
||||||
|
path: code
|
||||||
|
- name: Exec Pipeline
|
||||||
|
working-directory: ./devops
|
||||||
|
run: go run demo.go
|
||||||
@ -10,7 +10,7 @@ class LoginController extends Controller
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Display login page.
|
* Display login page.
|
||||||
*
|
*
|
||||||
* @return Renderable
|
* @return Renderable
|
||||||
*/
|
*/
|
||||||
public function show()
|
public function show()
|
||||||
@ -20,9 +20,9 @@ public function show()
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle account login request
|
* Handle account login request
|
||||||
*
|
*
|
||||||
* @param LoginRequest $request
|
* @param LoginRequest $request
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function login(LoginRequest $request)
|
public function login(LoginRequest $request)
|
||||||
@ -34,11 +34,7 @@ public function login(LoginRequest $request)
|
|||||||
->withErrors(trans('auth.failed'));
|
->withErrors(trans('auth.failed'));
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
|
|
||||||
$user = Auth::getProvider()->retrieveByCredentials($credentials);
|
$user = Auth::getProvider()->retrieveByCredentials($credentials);
|
||||||
if($user->active != true){
|
|
||||||
return redirect()->to('login');
|
|
||||||
}
|
|
||||||
|
|
||||||
Auth::login($user);
|
Auth::login($user);
|
||||||
|
|
||||||
@ -47,14 +43,14 @@ public function login(LoginRequest $request)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle response after user authenticated
|
* Handle response after user authenticated
|
||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param Auth $user
|
* @param Auth $user
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
protected function authenticated(Request $request, $user)
|
protected function authenticated(Request $request, $user)
|
||||||
{
|
{
|
||||||
return redirect()->intended();
|
return redirect()->intended();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4,7 +4,7 @@
|
|||||||
"description": "The Laravel Framework.",
|
"description": "The Laravel Framework.",
|
||||||
"keywords": ["framework", "laravel"],
|
"keywords": ["framework", "laravel"],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^8.0.2",
|
"php": "^8.0.2",
|
||||||
"guzzlehttp/guzzle": "^7.2",
|
"guzzlehttp/guzzle": "^7.2",
|
||||||
"laravel/framework": "^9.19",
|
"laravel/framework": "^9.19",
|
||||||
@ -32,6 +32,7 @@
|
|||||||
"Tests\\": "tests/"
|
"Tests\\": "tests/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"post-autoload-dump": [
|
"post-autoload-dump": [
|
||||||
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
|
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
|
||||||
|
|||||||
151
demo.go
Normal file
151
demo.go
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"dagger.io/dagger"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
if err := buildstaging(context.Background()); err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildstaging(ctx context.Context) error {
|
||||||
|
fmt.Println("Inicializando deploy")
|
||||||
|
os.Chdir("./..")
|
||||||
|
|
||||||
|
fmt.Println("Levantar base de datos")
|
||||||
|
uniqueVolume := client.CacheVolume(fmt.Sprintf("pgdata-%d", time.Now().UnixNano()))
|
||||||
|
databaseDevelopment := client.Container().
|
||||||
|
From("postgres:16").
|
||||||
|
WithEnvVariable("POSTGRES_PASSWORD", "secret").
|
||||||
|
WithEnvVariable("POSTGRES_USER", "savne").
|
||||||
|
WithEnvVariable("POSTGRES_DB", "sav_net_test").
|
||||||
|
WithExposedPort(5432).
|
||||||
|
WithMountedCache("/var/lib/postgresql/data", uniqueVolume).
|
||||||
|
WithExec([]string{"postgres"}).
|
||||||
|
AsService()
|
||||||
|
|
||||||
|
client.Pipeline("Migraciones")
|
||||||
|
migrations, err := client.Container(dagger.ContainerOpts{Platform: "linux/amd64"}).
|
||||||
|
From("liquibase/liquibase").
|
||||||
|
WithServiceBinding("sav-net-db", databaseDevelopment).
|
||||||
|
WithDirectory("/project/migrations", client.Host().Directory("./dbmigrations/migrations")).
|
||||||
|
WithFile("/project/liquibase.properties", client.Host().File("liquibase.properties")).
|
||||||
|
WithWorkdir("/project").
|
||||||
|
WithExec([]string{"sleep", "20"}).
|
||||||
|
WithExec([]string{"liquibase", "--defaultsFile=/project/liquibase.properties", "update"}).
|
||||||
|
Stdout(ctx)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("Correr Migraciones: \n%s", migrations)
|
||||||
|
|
||||||
|
client.Pipeline("Test de cobertura")
|
||||||
|
hostDirectory := client.Host().Directory(".")
|
||||||
|
containerApp := hostDirectory.
|
||||||
|
DockerBuild(dagger.DirectoryDockerBuildOpts{
|
||||||
|
Dockerfile: "/devops/.devops/development/DockerfileTest",
|
||||||
|
}).
|
||||||
|
WithWorkdir("/var/www/app").
|
||||||
|
WithServiceBinding("sav-net-db", databaseDevelopment).
|
||||||
|
WithExec([]string{"composer", "install"}).
|
||||||
|
|
||||||
|
addr, err := containerApp.
|
||||||
|
WithExec([]string{"vendor/bin/phpunit", "--coverage-clover", ".qa/coverage/report.xml", "/var/www/app/src"}).
|
||||||
|
Directory("/var/www/app/.qa").
|
||||||
|
Export(ctx, "./code/.qa")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
fmt.Println("Se ejecutaron los test:", addr)
|
||||||
|
|
||||||
|
fmt.Println("Ejecutar sonarScanner")
|
||||||
|
sonarScanner, err := client.Container(dagger.ContainerOpts{Platform: "linux/amd64"}).
|
||||||
|
From("sonarsource/sonar-scanner-cli").
|
||||||
|
WithEnvVariable("URL", os.Getenv("HOST")).
|
||||||
|
WithEnvVariable(
|
||||||
|
"SONAR_SCANNER_OPTS",
|
||||||
|
"-Dsonar.projectKey=Savnet "+
|
||||||
|
"-Dsonar.exclusions=public/**/*,vendor/**/*,storage/**/*,tests/**/*,.qa/**/*,.devops/**/* "+
|
||||||
|
"-Dsonar.php.coverage.reportPaths=.qa/coverage/report.xml "+
|
||||||
|
"-Dsonar.php.tests.reportPath=.qa/coverage/report-tests.xml -Dsonar.projectBaseDir=/var/www/app").
|
||||||
|
WithEnvVariable("TOKEN", os.Getenv("SAV_DEVELOP")).
|
||||||
|
WithDirectory("/var/www/app/app", client.Host().Directory("./code/app")).
|
||||||
|
WithWorkdir("/var/www/app").
|
||||||
|
Stdout(ctx)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
log.Printf("sonarScanner: \n%s", sonarScanner)
|
||||||
|
|
||||||
|
time.Sleep(420 * time.Second)
|
||||||
|
|
||||||
|
dataDevelopment := PayloadDevelopment{
|
||||||
|
NombreApp: "SavNet",
|
||||||
|
EntornoApp: "Development",
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("Quality Gate failed")
|
||||||
|
url := os.Getenv("HOST") + "project_status?projectKey=Savnet"
|
||||||
|
req, _ := http.NewRequest("GET", url, nil)
|
||||||
|
req.Header.Add("Authorization", os.Getenv("SAV_DEVELOP"))
|
||||||
|
resp, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Error executing request: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
var result struct {
|
||||||
|
ProjectStatus struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
} `json:"projectStatus"`
|
||||||
|
}
|
||||||
|
json.NewDecoder(resp.Body).Decode(&result)
|
||||||
|
if result.ProjectStatus.Status != "OK" {
|
||||||
|
url_ := os.Getenv("TOKEN_FAILED")
|
||||||
|
sendNotificationDevelopment(url_, dataDevelopment)
|
||||||
|
log.Fatal("Quality Gate failed!")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
fmt.Printf("Estado: %s\n", result)
|
||||||
|
|
||||||
|
image := hostDirectory.
|
||||||
|
DockerBuild(dagger.DirectoryDockerBuildOpts{
|
||||||
|
Dockerfile: "Dockerfile",
|
||||||
|
}).
|
||||||
|
WithWorkdir("/var/www/app").
|
||||||
|
WithExec([]string{"composer", "install"}).
|
||||||
|
WithEnvVariable("APP_VERSION", appVersion)
|
||||||
|
|
||||||
|
publishedVersion, err := image.
|
||||||
|
WithRegistryAuth(
|
||||||
|
os.Getenv("SAV_OST"),
|
||||||
|
os.Getenv("SAV_SER"),
|
||||||
|
secret).
|
||||||
|
Publish(ctx, os.Getenv("SAV_HOST")+"savnet:"+version)
|
||||||
|
|
||||||
|
fmt.Println("Enviando notificación a Rocket.Chat...")
|
||||||
|
url_ := os.Getenv("SAV_DEVELOPMENT")
|
||||||
|
chatMatriz := sendNotification(url_, dataDevelopment)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error al enviar la notificación:", chatMatriz)
|
||||||
|
} else {
|
||||||
|
fmt.Println("Notificación enviada correctamente")
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("Finalizo deploy")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user