Skip to content

Commit f97440a

Browse files
devtronnishant-d
devtron
authored andcommitted
Initial commit
0 parents  commit f97440a

File tree

8,624 files changed

+4231374
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

8,624 files changed

+4231374
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea
2+
devtron

App.go

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*
2+
* Copyright (c) 2020 Devtron Labs
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package main
19+
20+
import (
21+
"context"
22+
"github.com/devtron-labs/devtron/api/router"
23+
"github.com/devtron-labs/devtron/api/sse"
24+
"github.com/devtron-labs/devtron/client/argocdServer"
25+
"github.com/devtron-labs/devtron/client/pubsub"
26+
"github.com/devtron-labs/devtron/internal/middleware"
27+
"github.com/devtron-labs/devtron/pkg/user"
28+
"fmt"
29+
"github.com/argoproj/argo-cd/util/session"
30+
"github.com/casbin/casbin"
31+
"github.com/go-pg/pg"
32+
_ "github.com/lib/pq"
33+
"go.uber.org/zap"
34+
"log"
35+
"net/http"
36+
"os"
37+
"time"
38+
)
39+
40+
type App struct {
41+
MuxRouter *router.MuxRouter
42+
Logger *zap.SugaredLogger
43+
SSE *sse.SSE
44+
Enforcer *casbin.Enforcer
45+
sessionManager *session.SessionManager
46+
server *http.Server
47+
db *pg.DB
48+
pubsubClient *pubsub.PubSubClient
49+
}
50+
51+
func NewApp(router *router.MuxRouter,
52+
Logger *zap.SugaredLogger,
53+
sse *sse.SSE,
54+
manager *session.SessionManager,
55+
versionService argocdServer.VersionService,
56+
enforcer *casbin.Enforcer,
57+
db *pg.DB,
58+
pubsubClient *pubsub.PubSubClient) *App {
59+
//check argo connection
60+
err := versionService.CheckVersion()
61+
if err != nil {
62+
log.Panic(err)
63+
}
64+
app := &App{MuxRouter: router, Logger: Logger, SSE: sse, Enforcer: enforcer, sessionManager: manager, db: db, pubsubClient: pubsubClient}
65+
return app
66+
}
67+
68+
func (app *App) Start() {
69+
70+
/* RequestDuration := prometheus.NewHistogramVec(prometheus.HistogramOpts{
71+
Name: "request_duration_seconds",
72+
Help: "Time (in seconds) spent serving HTTP requests.",
73+
Buckets: prometheus.DefBuckets,
74+
}, []string{"method", "route", "status_code", "ws"})
75+
prometheus.MustRegister(RequestDuration)
76+
prometheus.Ins*/
77+
//instrument:=middleware.Instrument{
78+
// Duration: RequestDuration,
79+
//}
80+
port := 8080 //TODO: extract from environment variable
81+
app.Logger.Debugw("starting server")
82+
app.Logger.Infow("starting server on ", "port", port)
83+
app.MuxRouter.Init()
84+
//authEnforcer := casbin2.Create()
85+
86+
server := &http.Server{Addr: fmt.Sprintf(":%d", port), Handler: user.Authorizer(app.Enforcer, app.sessionManager)(app.MuxRouter.Router)}
87+
88+
app.MuxRouter.Router.Use(middleware.PrometheusMiddleware)
89+
app.server = server
90+
err := server.ListenAndServe()
91+
//err := http.ListenAndServe(fmt.Sprintf(":%d", port), auth.Authorizer(app.Enforcer, app.sessionManager)(app.MuxRouter.Router))
92+
if err != nil {
93+
app.Logger.Errorw("error in startup", "err", err)
94+
os.Exit(2)
95+
}
96+
}
97+
98+
func (app *App) Stop() {
99+
app.Logger.Infow("orchestrator shutdown initiating")
100+
timeoutContext, _ := context.WithTimeout(context.Background(), 5*time.Second)
101+
app.Logger.Infow("closing router")
102+
err := app.server.Shutdown(timeoutContext)
103+
if err != nil {
104+
app.Logger.Errorw("error in mux router shutdown", "err", err)
105+
}
106+
app.Logger.Infow("closing db connection")
107+
err = app.db.Close()
108+
if err != nil {
109+
app.Logger.Errorw("error in closing db connection", "err", err)
110+
}
111+
nc := app.pubsubClient.Conn.NatsConn()
112+
//closing nats
113+
err = app.pubsubClient.Conn.Close()
114+
if err != nil {
115+
app.Logger.Errorw("error in closing stan", "err", err)
116+
}
117+
err = nc.Drain()
118+
if err != nil {
119+
app.Logger.Errorw("error in draining nats", "err", err)
120+
}
121+
nc.Close()
122+
app.Logger.Infow("housekeeping done. exiting now")
123+
}

CONTRIBUTING.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# How to Contribute
2+
3+
Devtron is [Apache 2.0 licensed](LICENSE) and accepts contributions via GitHub
4+
pull requests. This document outlines some of the conventions on development
5+
workflow, commit message formatting, contact points and other resources to make
6+
it easier to get your contribution accepted.
7+
8+
We gratefully welcome improvements to issues and documentation as well as to code.
9+
10+
## Certificate of Origin
11+
12+
By contributing to this project you agree to the Developer Certificate of
13+
Origin (DCO). This document was created by the Linux Kernel community and is a
14+
simple statement that you, as a contributor, have the legal right to make the
15+
contribution. No action from you is required, but it's a good idea to see the
16+
[DCO](DCO) file for details before you start contributing code to Devtron.
17+
18+
## Communications
19+
20+
The project uses discord for communication:
21+
22+
To join the conversation, simply join the **[discord](https://discord.gg/wRspyec)** and use the __#contrib__ channel.
23+
24+
## Code Structure
25+
26+
Devtron has following components
27+
28+
- [devtron](https://github.com/devtron-labs/devtron.git) main co-ordinating engine
29+
- [git sensor](https://github.com/devtron-labs/git-sensor.git) microservice for watching and interacting with git
30+
- [ci runner](https://github.com/devtron-labs/ci-runner.git) Devtron runner for executing jobs
31+
- [guard](https://github.com/devtron-labs/guard.git) A kubernetes validating webhook for policy inforcement
32+
- [imge-scanner](https://github.com/devtron-labs/image-scanner.git) microservice for docker image vulnerability scanning
33+
- [kubewatch](https://github.com/devtron-labs/kubewatch.git) microservice for k8s event filtering and recording
34+
- [lens](https://github.com/devtron-labs/lens.git) microservice for performing analytical task
35+
- [dashboard](https://github.com/devtron-labs/dashboard.git) Ui for devtron written in react js
36+
37+
38+
39+

DCO

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Developer Certificate of Origin
2+
Version 1.1
3+
4+
Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
5+
1 Letterman Drive
6+
Suite D4700
7+
San Francisco, CA, 94129
8+
9+
Everyone is permitted to copy and distribute verbatim copies of this
10+
license document, but changing it is not allowed.
11+
12+
13+
Developer's Certificate of Origin 1.1
14+
15+
By making a contribution to this project, I certify that:
16+
17+
(a) The contribution was created in whole or in part by me and I
18+
have the right to submit it under the open source license
19+
indicated in the file; or
20+
21+
(b) The contribution is based upon previous work that, to the best
22+
of my knowledge, is covered under an appropriate open source
23+
license and I have the right under that license to submit that
24+
work with modifications, whether created in whole or in part
25+
by me, under the same open source license (unless I am
26+
permitted to submit under a different license), as indicated
27+
in the file; or
28+
29+
(c) The contribution was provided directly to me by some other
30+
person who certified (a), (b) or (c) and I have not modified
31+
it.
32+
33+
(d) I understand and agree that this project and the contribution
34+
are public and that a record of the contribution (including all
35+
personal information I submit with it, including my sign-off) is
36+
maintained indefinitely and may be redistributed consistent with
37+
this project or the open source license(s) involved.

Dockerfile

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM golang:1.12.9-alpine3.9 AS build-env
2+
RUN echo $GOPATH
3+
4+
RUN apk add --no-cache git gcc musl-dev
5+
RUN apk add --update make
6+
RUN go get github.com/google/wire/cmd/wire
7+
WORKDIR /go/src/github.com/devtron-labs/devtron
8+
ADD . /go/src/github.com/devtron-labs/devtron/
9+
RUN GOOS=linux make
10+
11+
FROM alpine:3.9
12+
RUN apk add --no-cache ca-certificates
13+
RUN echo pwd
14+
COPY --from=build-env /go/src/github.com/devtron-labs/devtron/devtron .
15+
COPY --from=build-env /go/src/github.com/devtron-labs/devtron/auth_model.conf .
16+
COPY --from=build-env /go/src/github.com/devtron-labs/devtron/vendor/github.com/argoproj/argo-cd/assets/ /go/src/github.com/devtron-labs/devtron/vendor/github.com/argoproj/argo-cd/assets
17+
COPY --from=build-env /go/src/github.com/devtron-labs/devtron/scripts/devtron-reference-helm-charts scripts/devtron-reference-helm-charts
18+
CMD ["./devtron"]

0 commit comments

Comments
 (0)