Skip to content

Commit ffa57b4

Browse files
authored
Git sync (#72)
* Refactor git * fixes, better entrypoint * fix command * Use committer timestamp * Enable git_sync plugin * Fix entrypoint handler * Enable heartbeat plugin * Enable plugins only if worker is running * Disable git_sync by default
1 parent 35f6af6 commit ffa57b4

25 files changed

+665
-225
lines changed

Dockerfile

+17-8
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,28 @@ RUN mkdir -p $APP_PATH
88
WORKDIR $APP_PATH
99

1010
RUN apk -U add alpine-sdk libgit2-dev git gcc nodejs
11-
COPY ./dashboard/package.json $APP_PATH/dashboard/package.json
12-
COPY ./server/configs/codeflow.yml /etc/codeflow.yml
13-
RUN cd $APP_PATH/dashboard/ && npm install
14-
COPY . /go/src/github.com/checkr/codeflow
11+
RUN go get github.com/cespare/reflex
12+
RUN npm install gitbook-cli -g
13+
14+
WORKDIR $APP_PATH/dashboard
15+
COPY ./dashboard/package.json ./package.json
16+
RUN npm install
17+
18+
WORKDIR $APP_PATH/docs
19+
COPY ./docs/package.json ./package.json
20+
RUN npm install
21+
22+
COPY . $APP_PATH
1523

1624
WORKDIR $APP_PATH/server
1725
RUN go build -i -o /go/bin/codeflow .
18-
RUN go get github.com/cespare/reflex
26+
27+
WORKDIR $APP_PATH/docs
28+
RUN gitbook install && gitbook build
1929

2030
WORKDIR $APP_PATH/dashboard
2131
RUN npm run build
2232

23-
RUN npm install gitbook-cli -g
24-
RUN cd $APP_PATH/docs && npm install && gitbook install && gitbook build
25-
2633
WORKDIR $APP_PATH
34+
35+
ENTRYPOINT ["./docker-entrypoint.sh"]

Makefile

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
.PHONY: up server dashboard build
22

33
up:
4-
docker-compose run --rm server /bin/sh -c 'cd server/ && go run main.go --config ./configs/codeflow.dev.yml migrate up'
4+
docker-compose run --rm server go run main.go --config ./configs/codeflow.dev.yml migrate up
55
docker-compose up -d redis mongo
66
docker-compose up server dashboard
77

88
build:
99
docker-compose build server
1010
docker-compose build dashboard
1111

12-
dashboard:
13-
cd ./dashboard && npm run start
14-
15-
server:
16-
cd ./server && reflex -c reflex.conf
12+
destroy:
13+
docker-compose stop
14+
docker-compose rm -f

dashboard/public/css/application.css

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ body {
44
font-weight: 300;
55
letter-spacing: 0;
66
}
7+
ul
8+
{
9+
list-style-type: none;
10+
}
711
.navbar-full {
812
margin-bottom: 50px;
913
}
+49-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React, { Component } from 'react'
2-
import { Button, Form, FormGroup, Label, Input } from 'reactstrap'
2+
import { Button, Form, FormGroup, Label, Input, FormText } from 'reactstrap'
33
import { Field, reduxForm } from 'redux-form'
4+
import { connect } from 'react-redux'
45

56

6-
class AddProjectForm extends Component {
7+
class AddProject extends Component {
78
renderInput(field) {
89
return (
910
<Input {...field.input} type={field.type} placeholder={field.placeholder} />
@@ -16,16 +17,49 @@ class AddProjectForm extends Component {
1617
)
1718
}
1819

20+
renderGitUrl() {
21+
let { formValues } = this.props
22+
if (formValues && formValues.values.gitProtocol === "HTTPS") {
23+
return (
24+
<FormGroup>
25+
<Label for="gitUrl">Git HTTPS Url</Label>
26+
<Field name="gitUrl" component={this.renderInput} type="text" placeholder="https://github.com/checkr/codeflow.git"/>
27+
</FormGroup>
28+
)
29+
} else {
30+
return (
31+
<FormGroup>
32+
<Label for="gitUrl">Git SSH Url</Label>
33+
<Field name="gitUrl" component={this.renderInput} type="text" placeholder="[email protected]:checkr/codeflow.git"/>
34+
</FormGroup>
35+
)
36+
}
37+
}
38+
1939
render() {
2040
const { onSubmit } = this.props
2141
return (
2242
<Form onSubmit={onSubmit}>
2343
<FormGroup>
24-
<Label for="gitSshUrl">Git SSH Url</Label>
25-
<Field name="gitSshUrl" component={this.renderInput} type="text" placeholder="[email protected]:checkr/codeflow.git"/>
44+
<Label>Protocol</Label>
45+
<FormGroup tag="fieldset">
46+
<FormGroup check>
47+
<Label check>
48+
<Field className="form-check-input" name={'gitProtocol'} component={this.renderInput} type="radio" value="SSH"/> SSH
49+
</Label>
50+
<FormText color="muted">Use SSH for private repositories</FormText>
51+
</FormGroup>
52+
<FormGroup check>
53+
<Label check>
54+
<Field className="form-check-input" name={'gitProtocol'} component={this.renderInput} type="radio" value="HTTPS"/> HTTPS
55+
</Label>
56+
<FormText color="muted">Use HTTPS for public repositories</FormText>
57+
</FormGroup>
58+
</FormGroup>
2659
</FormGroup>
27-
<FormGroup check>
28-
<Label check>
60+
{this.renderGitUrl()}
61+
<FormGroup>
62+
<Label>
2963
<Field name="bookmarked" component={this.renderCheckbox} type="checkbox"/> Add to my bookmarks
3064
</Label>
3165
</FormGroup>
@@ -36,6 +70,13 @@ class AddProjectForm extends Component {
3670
}
3771
}
3872

39-
export default reduxForm({
73+
const AddProjectForm = reduxForm({
4074
form: 'addProject'
41-
})(AddProjectForm)
75+
})(AddProject)
76+
77+
export default connect(
78+
state => {
79+
const formValues = state.form.addProject
80+
return { formValues: formValues, initialValues: {gitProtocol: "SSH", bookmarked: true} }
81+
}
82+
)(AddProjectForm)

dashboard/src/components/ProjectDeploy.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class ProjectDeploy extends Component {
9797
<div className="row media-body">
9898
<div className="col-xs-10">
9999
<strong>{this.renderFeatureHash(feature)} - {feature.message}</strong> <br/>
100-
<small className="text-muted">by <strong>{feature.user}</strong> {moment(feature._created).fromNow() } - {moment(feature._created).format('MMMM Do YYYY, h:mm:ss A')} </small>
100+
<small className="text-muted">by <strong>{feature.user}</strong> {moment(feature.created).fromNow() } - {moment(feature.created).format('MMMM Do YYYY, h:mm:ss A')} </small>
101101
</div>
102102
<div className="col-xs-2 flex-xs-middle">
103103
{this.state.featureHover === feature._id &&

dashboard/src/store/configureStore.dev.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ import { createStore, applyMiddleware, compose } from 'redux'
22
import thunk from 'redux-thunk'
33
import { createLogger } from 'redux-logger'
44
import rootReducer from '../reducers'
5-
import DevTools from '../containers/DevTools'
65
import { apiMiddleware } from 'redux-api-middleware'
76
import socketMiddleware from '../middleware/socket'
7+
//import DevTools from '../containers/DevTools'
88

99
const configureStore = preloadedState => {
1010
const store = createStore(
1111
rootReducer,
1212
preloadedState,
1313
compose(
1414
applyMiddleware(thunk, socketMiddleware, apiMiddleware, createLogger()),
15-
DevTools.instrument()
15+
//DevTools.instrument()
1616
)
1717
)
1818

docker-compose.yml

+16-6
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ services:
99
ports:
1010
- "${DOCKER_COMPOSE_MONGODB_PORT}:27017"
1111
server:
12-
command: make server
13-
image: codeflow:v003
12+
command: reflex -c reflex.conf
13+
image: codeflow:v004
1414
build:
1515
context: .
1616
args:
1717
- NODE_ENV=development
18+
environment:
19+
- WORKDIR=./server
1820
volumes:
1921
- ./server:/go/src/github.com/checkr/codeflow/server
2022
- /var/run/docker.sock:/var/run/docker.sock
@@ -26,12 +28,14 @@ services:
2628
- "redis"
2729
- "mongo"
2830
dashboard:
29-
command: make dashboard
30-
image: codeflow:v003
31+
command: npm run start
32+
image: codeflow:v004
3133
build:
3234
context: .
3335
args:
3436
- NODE_ENV=development
37+
environment:
38+
- WORKDIR=./dashboard
3539
volumes:
3640
- ./dashboard:/go/src/github.com/checkr/codeflow/dashboard
3741
ports:
@@ -41,8 +45,14 @@ services:
4145
- ./dashboard/.env
4246
- ./dashboard/.env.development
4347
docs:
44-
command: gitbook serve docs
45-
image: codeflow:v003
48+
command: gitbook serve
49+
image: codeflow:v004
50+
build:
51+
context: .
52+
args:
53+
- NODE_ENV=development
54+
environment:
55+
- WORKDIR=./docs
4656
volumes:
4757
- ./docs:/go/src/github.com/checkr/codeflow/docs
4858
ports:

docker-entrypoint.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
WORKDIR=${WORKDIR-.}
3+
4+
if echo "$1" | grep -q "WORKDIR="; then
5+
export $1
6+
shift
7+
fi
8+
9+
cd $WORKDIR
10+
exec "$@"

docs/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"url": "https://github.com/checkr/codeflow/issues"
1717
},
1818
"dependencies": {
19-
"pushstate-server": "^2.1.0"
19+
"pushstate-server": "^2.2.2"
2020
},
2121
"homepage": "https://github.com/checkr/codeflow"
2222
}

docs/server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
var server = require('pushstate-server');
1010
var build = "./_book"
1111

12-
var port = process.env.PORT || 3000
12+
var port = process.env.DOCS_PORT || 4000
1313
var app = server.start({
1414
port: port,
1515
directory: build

server/agent/agent.go

+15-9
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ func (a *Agent) enablePlugin(name string) error {
135135
return nil
136136
}
137137

138+
if viper.GetInt("plugins."+name+".workers") <= 0 {
139+
return nil
140+
}
141+
138142
for _, rp := range a.Plugins {
139143
if rp.Name == name {
140144
rp.Enabled = true
@@ -155,22 +159,24 @@ func (a *Agent) flusher() {
155159
ev_handled := false
156160

157161
for _, plugin := range a.Plugins {
158-
subscribedTo := plugin.Plugin.Subscribe()
159-
if SliceContains(e.PayloadModel, subscribedTo) || SliceContains(e.Name, subscribedTo) {
160-
ev_handled = true
161-
if a.Queueing {
162-
log.Printf("Enqueue event %v for %v\n", e.Name, plugin.Name)
163-
workers.Enqueue(plugin.Name, "Event", e)
164-
} else {
165-
plugin.Plugin.Process(e)
162+
if plugin.Enabled {
163+
subscribedTo := plugin.Plugin.Subscribe()
164+
if SliceContains(e.PayloadModel, subscribedTo) || SliceContains(e.Name, subscribedTo) {
165+
ev_handled = true
166+
if a.Queueing {
167+
log.Printf("Enqueue event %v for %v\n", e.Name, plugin.Name)
168+
workers.Enqueue(plugin.Name, "Event", e)
169+
} else {
170+
plugin.Plugin.Process(e)
171+
}
166172
}
167173
}
168174
}
169175

170176
if a.TestEvents != nil {
171177
a.TestEvents <- e
172178
} else if !ev_handled {
173-
log.Printf("Event not handled by any plugin: ", e.Name)
179+
log.Printf("Event not handled by any plugin: %s\n", e.Name)
174180
spew.Dump(e)
175181
}
176182
}

server/configs/codeflow.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ plugins:
5959
registry_username: ""
6060
registry_password: ""
6161
registry_user_email: ""
62-
build_path: "/tmp"
6362
docker_host: "unix:///var/run/docker.sock"
63+
workdir: "/tmp/docker_build"
6464
kubedeploy:
6565
workers: 1
6666
kubeconfig: "/etc/secrets/kubeconfig"
@@ -74,3 +74,8 @@ plugins:
7474
slack:
7575
workers: 1
7676
webhook_url: ""
77+
git_sync:
78+
workers: 0
79+
workdir: "/tmp/git_sync"
80+
heartbeat:
81+
workers: 0

server/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
_ "github.com/checkr/codeflow/server/plugins/codeflow"
2020
_ "github.com/checkr/codeflow/server/plugins/codeflow/migrations"
2121
_ "github.com/checkr/codeflow/server/plugins/docker_build"
22+
_ "github.com/checkr/codeflow/server/plugins/git_sync"
2223
_ "github.com/checkr/codeflow/server/plugins/heartbeat"
2324
_ "github.com/checkr/codeflow/server/plugins/kubedeploy"
2425
_ "github.com/checkr/codeflow/server/plugins/slack"

0 commit comments

Comments
 (0)