Skip to content

Commit 93e8726

Browse files
committed
Initial commit
0 parents  commit 93e8726

File tree

21 files changed

+985
-0
lines changed

21 files changed

+985
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*' # v0.4.4
7+
8+
jobs:
9+
10+
build:
11+
name: Create Release
12+
runs-on: ubuntu-latest
13+
steps:
14+
15+
- name: Setup
16+
id: go
17+
uses: actions/setup-go@v2
18+
with:
19+
go-version: ^1.14
20+
21+
- name: Checkout
22+
id: setup
23+
uses: actions/checkout@v2
24+
25+
- name: Tidy
26+
run: |
27+
go mod tidy
28+
go mod vendor
29+
30+
- name: Test
31+
run: go test -v -count=1 -race ./...
32+
33+
- name: Version
34+
id: get_version
35+
run: echo ::set-env name=RELEASE_VERSION::$(echo ${GITHUB_REF:10})
36+
37+
- name: Release
38+
id: release-step
39+
uses: actions/create-release@v1
40+
env:
41+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42+
with:
43+
tag_name: ${{ github.ref }}
44+
release_name: Release ${{ github.ref }}
45+
body: Automatic release
46+
draft: false
47+
prerelease: false
48+
49+
- name: Image
50+
uses: elgohr/Publish-Docker-Github-Action@master
51+
env:
52+
VERSION: ${{ env.RELEASE_VERSION }}
53+
with:
54+
name: ${{ secrets.DOCKER_USERNAME }}/starter
55+
username: ${{ secrets.DOCKER_USERNAME }}
56+
password: ${{ secrets.DOCKER_PASSWORD }}
57+
buildargs: VERSION
58+
tags: "latest,${{ env.RELEASE_VERSION }}"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
8+
build:
9+
name: Test Push
10+
runs-on: ubuntu-latest
11+
steps:
12+
13+
- name: Setup
14+
id: go
15+
uses: actions/setup-go@v2
16+
with:
17+
go-version: ^1.14
18+
19+
- name: Checkout
20+
id: setup
21+
uses: actions/checkout@v2
22+
23+
- name: Tidy
24+
run: |
25+
go mod tidy
26+
go mod vendor
27+
28+
- name: Test
29+
run: go test -v -count=1 -race ./...
30+
31+

.gitignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out
13+
14+
# mac
15+
.DS_Store
16+
17+
# bin
18+
bin
19+
vendor

Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM golang:1.14.3 as builder
2+
3+
WORKDIR /src/
4+
COPY . /src/
5+
6+
ARG APP_VERSION=v0.0.1-default
7+
8+
ENV APP_VERSION=$APP_VERSION
9+
ENV GO111MODULE=on
10+
11+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
12+
go build -a -tags netgo -ldflags \
13+
"-w -extldflags '-static' -X main.AppVersion=${APP_VERSION}" \
14+
-mod vendor -o ./service .
15+
16+
FROM gcr.io/distroless/static:nonroot
17+
COPY --from=builder /src/service .
18+
19+
ENTRYPOINT ["./service"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Mark Chmarny
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
SERVICE_NAME =starter
2+
RELEASE_VERSION =v0.1.4
3+
DOCKER_USERNAME ?=$(DOCKER_USER)
4+
5+
.PHONY: mod test run build exec image show imagerun lint clean, tag
6+
all: test
7+
8+
mod: ## Updates the go modules and vendors all dependencies
9+
go mod tidy
10+
go mod vendor
11+
12+
test: mod ## Tests the entire project
13+
go test -v -count=1 -race ./...
14+
# go test -v -count=1 -run TestMakeCPUEvent ./...
15+
16+
run: mod ## Runs the uncompiled code
17+
go run handler.go main.go
18+
19+
build: mod ## Builds local release binary
20+
env CGO_ENABLED=0 go build -ldflags "-X main.Version=$(RELEASE_VERSION)" \
21+
-mod vendor -o bin/$(SERVICE_NAME) .
22+
23+
exec: build ## Builds binary and runs it in Dapr
24+
dapr run --app-id $(SERVICE_NAME) \
25+
--app-port 8080 \
26+
--protocol http \
27+
--port 3500 \
28+
--components-path ./config \
29+
bin/$(SERVICE_NAME)
30+
31+
event: ## Publishes sample message to Dapr pubsub API
32+
curl -v -d '{ "message": "hello" }' \
33+
-H "Content-type: application/json" \
34+
"http://localhost:3500/v1.0/publish/events"
35+
36+
image: mod ## Builds and publish docker image
37+
docker build --build-arg VERSION=$(RELEASE_VERSION) \
38+
-t "$(DOCKER_USERNAME)/$(SERVICE_NAME):$(RELEASE_VERSION)" .
39+
docker push "$(DOCKER_USERNAME)/$(SERVICE_NAME):$(RELEASE_VERSION)"
40+
41+
lint: ## Lints the entire project
42+
golangci-lint run --timeout=3m
43+
44+
tag: ## Creates release tag
45+
git tag $(RELEASE_VERSION)
46+
git push origin $(RELEASE_VERSION)
47+
48+
clean: ## Cleans all runtime generated directory
49+
go clean
50+
rm -fr ./bin/*
51+
52+
help: ## Display available commands
53+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk \
54+
'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# dapr-starter
2+
3+
This Dapr starter project accelerates the development of new Dapr services in `go`. It includes `make` commands for:
4+
5+
* `test` - Tests the entire project
6+
* `run` - Runs the uncompiled code
7+
* `build` - Builds local release binary
8+
* `exec` - Builds binary and runs it in Dapr locally
9+
* `event` - Publishes sample message to Dapr pubsub API
10+
* `image` - Builds and publish docker image to Docker Hub
11+
* `lint` - Lints the entire project
12+
* `tag` - Creates release tag
13+
* `clean` - Cleans all runtime generated directory (bin, vendor)
14+
* `help` - Display available commands
15+
16+
This project also includes GitHub actions in [.github/workflows](.github/workflows) that test on each `push` and build images and mark release on each `tag`.
17+
18+
[![Test](https://github.com/mchmarny/dapr-starter/workflows/Test/badge.svg)](https://github.com/mchmarny/dapr-starter/actions?query=workflow%3ATest) ![Release](https://github.com/mchmarny/dapr-starter/workflows/Release/badge.svg?query=workflow%3ARelease) [![Go Report Card](https://goreportcard.com/badge/github.com/mchmarny/dapr-starter)](https://goreportcard.com/report/github.com/mchmarny/dapr-starter) ![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/mchmarny/dapr-starter)
19+
20+
## how to use
21+
22+
1. Start by clicking on the Use this template button above the file list
23+
2. Select the account you want to own the repository in the owner drop-down menu
24+
3. Name your repository and optionally add description
25+
4. Choose a repository visibility (Public, Internal, Public)
26+
5. Finally, click Create repository from template
27+
28+
## make it your own
29+
30+
After setting up the template, there is a few things you may want to change in your new project
31+
32+
### Makefile
33+
34+
* Change the `SERVICE_NAME` and `RELEASE_VERSION` variables
35+
* If you have not already defined the `DOCKER_USER` environment variable set it directly here
36+
37+
### go.mod
38+
39+
* Update line 1 in [go.mod](go.mod) file by changing the github username org name and the project name to your own (`module github.com/mchmarny/dapr-starter`)
40+
* Run `go mod tidy` and `go mod vendor`
41+
* Run `make build` to make sure everything works (check [bin](bin) folder for results)
42+
43+
### deployment files
44+
45+
If deploying to Kubernates you may also want to consider updating the components and deployment files in the [deploy](deploy) directory.
46+
47+
## Disclaimer
48+
49+
This is my personal project and it does not represent my employer. I take no responsibility for issues caused by this code. I do my best to ensure that everything works, but if something goes wrong, my apologies is all you will get.
50+
51+
## License
52+
53+
This software is released under the [MIT](./LICENSE)

config/binding.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: dapr.io/v1alpha1
2+
kind: Component
3+
metadata:
4+
name: example-http-binding
5+
spec:
6+
type: bindings.http
7+
metadata:
8+
- name: url
9+
value: https://http2.pro/api/v1
10+
- name: method
11+
value: GET
12+

config/pubsub.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: dapr.io/v1alpha1
2+
kind: Component
3+
metadata:
4+
name: events
5+
spec:
6+
type: pubsub.redis
7+
metadata:
8+
- name: redisHost
9+
value: localhost:6379
10+
- name: redisPassword
11+
value: ""

config/statestore.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: dapr.io/v1alpha1
2+
kind: Component
3+
metadata:
4+
name: store
5+
spec:
6+
type: state.redis
7+
metadata:
8+
- name: redisHost
9+
value: localhost:6379
10+
- name: redisPassword
11+
value: ""
12+
- name: actorStateStore
13+
value: "true"

0 commit comments

Comments
 (0)