Skip to content
This repository was archived by the owner on Jun 2, 2023. It is now read-only.

Commit 8b5496b

Browse files
committed
make a monorepo
1 parent 65bbf8f commit 8b5496b

File tree

253 files changed

+6640
-559
lines changed

Some content is hidden

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

253 files changed

+6640
-559
lines changed

.circleci/config.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ jobs:
77
- image: circleci/postgres:9.4
88
environment:
99
POSTGRES_USER: postgres
10-
POSTGRES_DB: api_prod
10+
POSTGRES_DB: api_test
1111

1212
working_directory: /go/src/github.com/golangci/golangci-api
1313
steps:
1414
- checkout
1515
- run: GO111MODULE=on go mod vendor
1616
- run: go get github.com/golangci/golangci-lint/cmd/golangci-lint
1717
- run: echo 'REDIS_URL="redis://localhost:6379"' >.env
18-
- run: echo 'DATABASE_URL="postgresql://postgres:test@localhost:5432/api_prod?sslmode=disable"' >.env.test
18+
- run: echo 'WEB_ROOT="https://golangci.com"' >>.env
19+
- run: echo 'DATABASE_URL="postgresql://postgres:test@localhost:5432/api_test?sslmode=disable"' >.env.test
1920
- run:
2021
name: install dockerize
2122
command: wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && sudo tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz

Makefile

+37-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
.PHONY: test
22

3-
build:
4-
go build -v ./app/cmd/...
5-
63
gen: gen_services
74
go generate ./...
85

@@ -16,16 +13,39 @@ prepare_env:
1613
awslocal sqs create-queue --queue-name primary
1714
awslocal sqs list-queues
1815

19-
run_dev:
16+
run_api:
2017
godotenv go run cmd/golangci-api/main.go
2118

19+
run_worker:
20+
godotenv go run cmd/golangci-worker/main.go
21+
2222
migrate_force_version:
2323
godotenv -f .env.test sh -c 'migrate -database $${DATABASE_URL} -path ./migrations force $${V}'
2424

25-
test:
25+
test_api:
2626
go test -v -parallel 1 -p 1 ./test/
27+
28+
test_lint:
2729
golangci-lint run -v
2830

31+
test_lint_dev:
32+
go run ../golangci-lint/cmd/golangci-lint/main.go run -v
33+
34+
test_api_dev:
35+
echo "DROP DATABASE api_test;" | docker-compose exec -T pg psql -U postgres
36+
echo "CREATE DATABASE api_test;" | docker-compose exec -T pg psql -U postgres
37+
make test_api
38+
39+
test_worker:
40+
go test -v -parallel 1 -p 1 ./pkg/worker/...
41+
42+
test_worker_dev:
43+
echo "FLUSHALL" | docker-compose exec -T redis redis-cli
44+
make test_worker
45+
46+
test: test_api test_worker test_lint
47+
test_dev: test_api_dev test_worker_dev test_lint_dev
48+
2949
connect_to_local_db:
3050
dc exec pg psql -U postgres -d api_prod
3151

@@ -38,3 +58,15 @@ deploy_lambda: build_lambda
3858

3959
deploy_cloudformation:
4060
aws cloudformation deploy --template ./deployments/cloudformation.yml --region us-east-1 --capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM --stack-name golangci
61+
62+
worker_test_repo:
63+
# set env vars PR, REPO
64+
SLOW_TESTS_ENABLED=1 go test -v ./analyze -run TestAnalyzeRepo
65+
66+
worker_test_repo_fake_github:
67+
# set env vars PR, REPO
68+
SLOW_TESTS_ENABLED=1 go test -v ./analyze/processors -count=1 -run TestProcessRepoWithFakeGithub
69+
70+
mod_update:
71+
GO111MODULE=on go mod verify
72+
GO111MODULE=on go mod tidy

Procfile

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
web: golangci-api
2+
worker: golangci-worker

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ PORT=3000
3434

3535
Tests need `.env.test` file, overriding options from `.env`. There can be something like this:
3636
```
37-
DATABASE_URL="postgresql://postgres:test@localhost:5432/api_prod?sslmode=disable"
37+
DATABASE_URL="postgresql://postgres:test@localhost:5432/api_test?sslmode=disable"
3838
DATABASE_DEBUG=1
3939
```
4040

4141
### How to run tests
4242
```
43-
echo "CREATE DATABASE api_prod;" | docker-compose exec -T pg psql -U postgres
43+
echo "CREATE DATABASE api_test;" | docker-compose exec -T pg psql -U postgres
4444
make test
4545
```
4646

cmd/buildrunner/main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package main
33
import (
44
"time"
55

6-
"github.com/golangci/golangci-api/pkg/app/buildagent/build"
7-
"github.com/golangci/golangci-shared/pkg/config"
8-
"github.com/golangci/golangci-shared/pkg/logutil"
6+
"github.com/golangci/golangci-api/internal/shared/config"
7+
"github.com/golangci/golangci-api/internal/shared/logutil"
8+
"github.com/golangci/golangci-api/pkg/buildagent/build"
99
)
1010

1111
func main() {

cmd/containers_orchestrator/main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package main
22

33
import (
4-
"github.com/golangci/golangci-api/pkg/app/buildagent/containers"
5-
"github.com/golangci/golangci-shared/pkg/config"
6-
"github.com/golangci/golangci-shared/pkg/logutil"
4+
"github.com/golangci/golangci-api/internal/shared/config"
5+
"github.com/golangci/golangci-api/internal/shared/logutil"
6+
"github.com/golangci/golangci-api/pkg/buildagent/containers"
77
)
88

99
func main() {

cmd/ensuredeps/main.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import (
77
"log"
88
"os"
99

10-
"github.com/golangci/golangci-api/pkg/goenv/command"
11-
"github.com/golangci/golangci-api/pkg/goenv/result"
12-
"github.com/golangci/golangci-shared/pkg/logutil"
10+
"github.com/golangci/golangci-api/internal/shared/logutil"
11+
"github.com/golangci/golangci-api/pkg/goenvbuild/command"
12+
"github.com/golangci/golangci-api/pkg/goenvbuild/result"
1313

14-
"github.com/golangci/golangci-api/pkg/goenv/ensuredeps"
14+
"github.com/golangci/golangci-api/pkg/goenvbuild/ensuredeps"
1515
)
1616

1717
func main() {

cmd/genservices/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func encode{{.Name}}Response(ctx context.Context, w http.ResponseWriter, respons
160160
`
161161

162162
func main() {
163-
root := flag.String("root", "pkg/app/services", "root of services")
163+
root := flag.String("root", "pkg/api/services", "root of services")
164164
flag.Parse()
165165

166166
if err := generate(*root); err != nil {

cmd/getrepoinfo/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import (
66
"log"
77
"os"
88

9-
"github.com/golangci/golangci-shared/pkg/logutil"
9+
"github.com/golangci/golangci-api/internal/shared/logutil"
1010

11-
"github.com/golangci/golangci-api/pkg/goenv/repoinfo"
11+
"github.com/golangci/golangci-api/pkg/goenvbuild/repoinfo"
1212
"github.com/pkg/errors"
1313
)
1414

cmd/goenvbuild/main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package main
22

33
import (
4-
"github.com/golangci/golangci-api/pkg/goenv"
5-
"github.com/golangci/golangci-shared/pkg/config"
6-
"github.com/golangci/golangci-shared/pkg/logutil"
4+
"github.com/golangci/golangci-api/internal/shared/config"
5+
"github.com/golangci/golangci-api/internal/shared/logutil"
6+
"github.com/golangci/golangci-api/pkg/goenvbuild"
77
)
88

99
func main() {

cmd/golangci-api/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package main
22

33
import (
4-
"github.com/golangci/golangci-api/pkg/app"
4+
"github.com/golangci/golangci-api/pkg/api"
55
)
66

77
func main() {

cmd/golangci-worker/main.go

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package main
2+
3+
import (
4+
"github.com/golangci/golangci-api/pkg/worker/analyze/analyzequeue"
5+
"github.com/golangci/golangci-api/pkg/worker/lib/queue"
6+
"github.com/sirupsen/logrus"
7+
)
8+
9+
func main() {
10+
queue.Init()
11+
analyzequeue.RegisterTasks()
12+
if err := analyzequeue.RunWorker(); err != nil {
13+
logrus.Fatalf("Can't run analyze worker: %s", err)
14+
}
15+
}

deployments/build_runner/Dockerfile

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# (cd deployments/build_runner && docker build -t golangci/build-runner .)
2+
FROM golang:1.11 as builder
3+
4+
ENV GOPATH=/go
5+
ENV GOBINPATH=$GOPATH/bin
6+
7+
WORKDIR ${GOPATH}
8+
9+
ENV DEP_RELEASE_TAG=v0.5.0
10+
RUN curl https://github.com/raw/golang/dep/master/install.sh | sh
11+
12+
ENV GLIDE_RELEASE_TAG=v0.13.2
13+
RUN (wget -O - https://github.com/Masterminds/glide/releases/download/${GLIDE_RELEASE_TAG}/glide-${GLIDE_RELEASE_TAG}-linux-amd64.tar.gz | tar -zxvf -) && \
14+
mv linux-amd64/glide ${GOBINPATH}/
15+
16+
ENV GOVENDOR_VERSION=v1.0.8
17+
RUN wget https://github.com/kardianos/govendor/releases/download/${GOVENDOR_VERSION}/govendor_linux_amd64 -O $GOBINPATH/govendor && \
18+
chmod a+x $GOBINPATH/govendor
19+
20+
ENV GODEP_VERSION=v80
21+
RUN wget https://github.com/tools/godep/releases/download/${GODEP_VERSION}/godep_linux_amd64 -O $GOBINPATH/godep && \
22+
chmod a+x $GOBINPATH/godep
23+
24+
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.12.3
25+
26+
WORKDIR ${GOPATH}/src/github.com/golangci/golangci-api
27+
RUN git clone https://github.com/golangci/golangci-api.git . && \
28+
git checkout e545e490e0c7a973a2b761ea6e2d4e45a4f489b9 && \
29+
GO111MODULE=on go mod vendor && \
30+
go install ./cmd/buildrunner && \
31+
go install ./cmd/goenvbuild
32+
33+
FROM golang:1.11
34+
35+
ENV GOPATH=/go
36+
ENV GOBINPATH=$GOPATH/bin
37+
ENV PATH=$PATH:/usr/local/go/bin:$GOBINPATH
38+
39+
COPY --from=builder ${GOPATH}/bin/* ${GOPATH}/bin/
40+
41+
WORKDIR /goapp
42+
43+
ENV PORT=7000 MAX_LIFETIME=30m
44+
45+
CMD ["buildrunner"]

deployments/cloudformation.yml

+44-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ Resources:
3535
Action: ["sqs:SendMessage", "sqs:ReceiveMessage", "sqs:ChangeMessageVisibility", "sqs:DeleteMessage"]
3636
Resource: !GetAtt devPrimaryQueue.Arn
3737
UserName: golangciDevUser
38+
golangciDevIsaevUser:
39+
Type: AWS::IAM::User
40+
Properties:
41+
Policies:
42+
- PolicyName: GolangciDevIsaevAccess
43+
PolicyDocument:
44+
Statement:
45+
- Effect: Allow
46+
Action: ["sqs:SendMessage", "sqs:ReceiveMessage", "sqs:ChangeMessageVisibility", "sqs:DeleteMessage"]
47+
Resource: !GetAtt devIsaevPrimaryQueue.Arn
48+
UserName: golangciDevIsaevUser
3849
golangciProdUserKeys:
3950
Type: AWS::IAM::AccessKey
4051
Properties:
@@ -43,6 +54,10 @@ Resources:
4354
Type: AWS::IAM::AccessKey
4455
Properties:
4556
UserName: !Ref golangciDevUser
57+
golangciDevIsaevUserKeys:
58+
Type: AWS::IAM::AccessKey
59+
Properties:
60+
UserName: !Ref golangciDevIsaevUser
4661
golangciTestUserKeys:
4762
Type: AWS::IAM::AccessKey
4863
Properties:
@@ -104,6 +119,25 @@ Resources:
104119
# KmsMasterKeyId: alias/aws/sqs
105120
# KmsDataKeyReusePeriodSeconds: 600
106121
MessageRetentionPeriod: 1209600 # 14d
122+
devIsaevPrimaryQueue:
123+
Type: AWS::SQS::Queue
124+
Properties:
125+
RedrivePolicy:
126+
deadLetterTargetArn: !GetAtt devIsaevDeadLetterPrimaryQueue.Arn
127+
maxReceiveCount: 5
128+
VisibilityTimeout: 60
129+
ReceiveMessageWaitTimeSeconds: 20 # save costs on polling
130+
# KmsMasterKeyId: alias/aws/sqs
131+
# KmsDataKeyReusePeriodSeconds: 600
132+
MessageRetentionPeriod: 345600 # 4d
133+
devIsaevDeadLetterPrimaryQueue:
134+
Type: AWS::SQS::Queue
135+
Properties:
136+
VisibilityTimeout: 60
137+
ReceiveMessageWaitTimeSeconds: 20 # save costs on polling
138+
# KmsMasterKeyId: alias/aws/sqs
139+
# KmsDataKeyReusePeriodSeconds: 600
140+
MessageRetentionPeriod: 1209600 # 14d
107141

108142
Outputs:
109143
primaryQueueURL:
@@ -125,6 +159,9 @@ Outputs:
125159
devPrimaryQueueURL:
126160
Description: "URL of the dev primary queue"
127161
Value: !Ref devPrimaryQueue
162+
devIsaevPrimaryQueueURL:
163+
Description: "URL of the dev Isaev primary queue"
164+
Value: !Ref devIsaevPrimaryQueue
128165
golangciProdUserAccessKey:
129166
Value: !Ref golangciProdUserKeys
130167
Description: AWSAccessKeyId of golangciProdUser user
@@ -142,4 +179,10 @@ Outputs:
142179
Description: AWSAccessKeyId of golangciDevUser user
143180
golangciDevUserSecretKey:
144181
Value: !GetAtt [golangciDevUserKeys, SecretAccessKey]
145-
Description: AWSSecretKey of golangciDevUser user
182+
Description: AWSSecretKey of golangciDevUser user
183+
golangciDevIsaevUserAccessKey:
184+
Value: !Ref golangciDevIsaevUserKeys
185+
Description: AWSAccessKeyId of golangciDevIsaevUser user
186+
golangciDevIsaevUserSecretKey:
187+
Value: !GetAtt [golangciDevIsaevUserKeys, SecretAccessKey]
188+
Description: AWSSecretKey of golangciDevIsaevUser user

0 commit comments

Comments
 (0)