Skip to content

Commit

Permalink
Update project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
g3force committed Apr 23, 2023
1 parent 52398a9 commit 249d483
Show file tree
Hide file tree
Showing 14 changed files with 213 additions and 142 deletions.
153 changes: 85 additions & 68 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
version: 2
version: 2.1
parameters:
cmds:
type: string
default: "ssl-vision-client ssl-vision-cli"

jobs:
frontend:
build_node:
resource_class: medium
docker:
- image: cimg/node:lts
steps:
Expand All @@ -18,99 +24,110 @@ jobs:
paths:
- frontend/dist/*

backend:
test_go:
resource_class: medium
docker:
- image: cimg/go:1.20
- image: cimg/go:1.20.2
steps:
- checkout
- attach_workspace:
at: .
- run: go get -v -t -d ./...
- run: go test -v ./...
- run:
working_directory: cmd/ssl-vision-client
command: |
GOOS=linux GOARCH=amd64 go build -o ../../release/ssl-vision-client_linux_amd64
GOOS=darwin GOARCH=amd64 go build -o ../../release/ssl-vision-client_darwin_amd64
GOOS=windows GOARCH=amd64 go build -o ../../release/ssl-vision-client_windows_amd64.exe
- run:
working_directory: cmd/ssl-vision-cli
command: |
GOOS=linux GOARCH=amd64 go build -o ../../release/ssl-vision-cli_linux_amd64
GOOS=darwin GOARCH=amd64 go build -o ../../release/ssl-vision-cli_darwin_amd64
GOOS=windows GOARCH=amd64 go build -o ../../release/ssl-vision-cli_windows_amd64.exe
- run: go test -v -covermode=count -coverprofile=count.out ./...
- run: go tool cover -html=count.out -o coverage.html
- store_artifacts:
path: coverage.html
destination: coverage

build_go:
resource_class: large
docker:
- image: cimg/go:1.20.2
steps:
- checkout
- attach_workspace:
at: .
- run: go get -v -t -d ./...
- run: |
set -u
version=${CIRCLE_TAG:-}
for cmd in << pipeline.parameters.cmds >>; do
GOOS=linux GOARCH=amd64 go build -o ./release/${cmd}_${version}_linux_amd64 ./cmd/${cmd}
GOOS=linux GOARCH=arm64 go build -o ./release/${cmd}_${version}_linux_arm64 ./cmd/${cmd}
GOOS=linux GOARCH=arm go build -o ./release/${cmd}_${version}_linux_arm ./cmd/${cmd}
GOOS=darwin GOARCH=amd64 go build -o ./release/${cmd}_${version}_darwin_amd64 ./cmd/${cmd}
GOOS=darwin GOARCH=arm64 go build -o ./release/${cmd}_${version}_darwin_arm64 ./cmd/${cmd}
GOOS=windows GOARCH=amd64 go build -o ./release/${cmd}_${version}_windows_amd64.exe ./cmd/${cmd}
done
- persist_to_workspace:
root: .
paths:
- release/*

publish-github-release:
publish_gh:
resource_class: small
docker:
- image: cimg/go:1.20
- image: cimg/go:1.20.2
steps:
- attach_workspace:
at: .
- run:
name: "Prepare artifacts"
working_directory: release
command: |
mkdir gh
mv ssl-vision-client_linux_amd64 gh/ssl-vision-client_${CIRCLE_TAG}_linux_amd64
mv ssl-vision-client_darwin_amd64 gh/ssl-vision-client_${CIRCLE_TAG}_darwin_amd64
mv ssl-vision-client_windows_amd64.exe gh/ssl-vision-client_${CIRCLE_TAG}_windows_amd64.exe
mv ssl-vision-cli_linux_amd64 gh/ssl-vision-cli_${CIRCLE_TAG}_linux_amd64
mv ssl-vision-cli_darwin_amd64 gh/ssl-vision-cli_${CIRCLE_TAG}_darwin_amd64
mv ssl-vision-cli_windows_amd64.exe gh/ssl-vision-cli_${CIRCLE_TAG}_windows_amd64.exe
- run:
name: "Publish Release on GitHub"
command: |
go install github.com/tcnksm/ghr@v0.16.0
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${CIRCLE_TAG} ./release/gh/
- run: |
set -u
go install github.com/tcnksm/ghr@v0.16.0
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete -generatenotes ${CIRCLE_TAG} ./release
docker:
build_docker:
resource_class: small
docker:
- image: cimg/base:2023.04
steps:
- checkout
- setup_remote_docker:
version: 20.10.18
- run: |
for cmd in << pipeline.parameters.cmds >>; do
docker build -f ./cmd/${cmd}/Dockerfile -t robocupssl/${cmd}:latest .
done
publish_docker:
resource_class: small
docker:
- image: cimg/base:2023.02
- image: cimg/base:2023.04
steps:
- checkout
- setup_remote_docker:
version: 20.10.18
- run: |
# Parse version from tag (removing 'v' prefix)
TAG=${CIRCLE_TAG:1}
TAG=${TAG:-latest}
docker build -t robocupssl/ssl-vision-client:$TAG .
docker login -u "${DOCKER_HUB_USERNAME}" -p "${DOCKER_HUB_PASSWORD}"
docker push robocupssl/ssl-vision-client:$TAG
docker build -t robocupssl/ssl-vision-cli:$TAG .
docker login -u "${DOCKER_HUB_USERNAME}" -p "${DOCKER_HUB_PASSWORD}"
docker push robocupssl/ssl-vision-cli:$TAG
for cmd in << pipeline.parameters.cmds >>; do
docker build -f ./cmd/${cmd}/Dockerfile -t robocupssl/${cmd}:${TAG} .
docker login -u "${DOCKER_HUB_USERNAME}" -p "${DOCKER_HUB_PASSWORD}"
docker push robocupssl/${cmd}:${TAG}
done
workflows:
version: 2
main:
build:
jobs:
- frontend:
filters:
tags:
only: /.*/
- backend:
requires:
- frontend
filters:
tags:
only: /.*/
- publish-github-release:
- build_node
- test_go:
requires: [ build_node ]
release:
jobs:
- build_node:
filters: { branches: { ignore: /.*/ }, tags: { only: /^v.*/ } }
- build_go:
requires: [ build_node ]
filters: { branches: { ignore: /.*/ }, tags: { only: /^v.*/ } }
- publish_gh:
context: github
requires:
- backend
filters:
branches:
ignore: /.*/
tags:
only: /^v.*/
- docker:
requires: [ build_go ]
filters: { branches: { ignore: /.*/ }, tags: { only: /^v.*/ } }
docker:
jobs:
- build_docker
- publish_docker:
context: docker hub
filters:
branches:
only: master
tags:
only: /^v.*/
filters: { branches: { only: master }, tags: { only: /^v.*/ } }
16 changes: 10 additions & 6 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/node_modules
/dist
/.git
/Dockerfile
/.idea
/.vscode
*
!cmd
!frontend
!internal
!pkg
!go.mod
!go.sum

frontend/node_modules
frontend/dist
8 changes: 4 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ root = true
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2

[*.proto]
indent_size = 4

[*.go]
[Makefile]
indent_style = tab

[*.{vue,yml,json}]
indent_size = 2
11 changes: 11 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
changelog:
categories:
- title: 🏕 Features
labels:
- '*'
exclude:
labels:
- dependencies
- title: 👒 Dependencies
labels:
- dependencies
28 changes: 19 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
.DS_Store
node_modules
/dist
/config/

# Editor directories and files
.idea/*
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw*
!.idea/runConfigurations

# local env files
.env.local
Expand All @@ -11,11 +21,11 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw*
# app-specific ignores
/*.json.stream

# Local installations
/.local

# Make cache
/.frontend
23 changes: 0 additions & 23 deletions Dockerfile

This file was deleted.

30 changes: 30 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
CMDS = ssl-vision-client ssl-vision-cli
DOCKER_TARGETS = $(addprefix docker-, $(CMDS))
.PHONY: all docker frontend install test run proto $(DOCKER_TARGETS)

all: install docker

docker: $(DOCKER_TARGETS)

$(DOCKER_TARGETS): docker-%:
docker build -f ./cmd/$*/Dockerfile -t $*:latest .

.frontend: $(shell find frontend/ -type f -not -path "frontend/node_modules/*")
cd frontend && \
npm install && \
npm run build && \
touch ../.frontend

frontend: .frontend

install: frontend
go install -v ./...

test: frontend
go test ./...

run: frontend
go run ./cmd/$(word 1,$(CMDS))

proto:
tools/generateProto.sh
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,27 @@ By default, the UI is available at http://localhost:8082

## Development

### Requirements

You need to install following dependencies first:

* Go
* Node

See [.circleci/config.yml](.circleci/config.yml) for required versions.
See [.circleci/config.yml](.circleci/config.yml) for compatible versions.

### Frontend

See [frontend/README.md](frontend/README.md)

### Build

Build and install all binaries:

```bash
make install
```

### Run

Run the backend:
Expand All @@ -41,8 +51,10 @@ Run the backend:
go run cmd/ssl-vision-client/main.go
```

### Build self-contained release binary
### Update generated protobuf code

```bash
./install.sh
Generate the code for the `.proto` files after you've changed anything in a `.proto` file with:

```shell
make proto
```
13 changes: 0 additions & 13 deletions cli.Dockerfile

This file was deleted.

Loading

0 comments on commit 249d483

Please sign in to comment.