Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mpppk committed Jun 26, 2020
0 parents commit e74e6ef
Show file tree
Hide file tree
Showing 56 changed files with 3,125 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
defaults: &defaults
docker:
- image: circleci/golang:1.14
environment:
GO111MODULE: "on"

version: 2
jobs:
test:
<<: *defaults
steps:
- checkout
- restore_cache:
keys:
- go-module-cache-v1-{{ checksum "~/project/go.sum" }}
- go-module-cache-v1-
- run: go mod download
- save_cache:
key: go-module-cache-v1-{{ checksum "~/project/go.sum" }}
paths:
- ~/go/pkg/mod/cache
- run: make setup
- run: make build
- run: make test
- run: make codecov

workflows:
version: 2
test_and_release:
jobs:
- test:
filters:
branches:
only: /.*/
tags:
only: /.*/
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dockerfile
88 changes: 88 additions & 0 deletions .github/workflows/gcp-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Build and Deploy to Cloud Run

on:
pull_request:
types: [synchronize, opened, reopened, closed]

env:
PROJECT: mpppk-workspace
HOSTNAME: asia.gcr.io
REGION: asia-northeast1
SERVICE: preview-${{ github.event.number }}

jobs:
setup-build-publish-deploy:
name: Setup, Build, Publish, and Deploy
if: github.event.action == 'opened' || github.event.action == 'reopened' || github.event.action == 'synchronize'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

# Setup gcloud CLI
- uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
with:
version: '274.0.0'
service_account_key: ${{ secrets.GCP_KEY }}

# Configure gcloud
- run: |
gcloud config set project ${PROJECT}
gcloud config set run/platform managed
gcloud config set run/region ${REGION}
gcloud auth configure-docker
# Build the Docker image
- name: Build
run: |
docker build -t ${HOSTNAME}/${PROJECT}/${SERVICE} .
# Publish the Docker image to GCR
- name: Publish
run: |
docker push ${HOSTNAME}/${PROJECT}/${SERVICE}
# Deploy the Docker image to the Cloud Run
- name: Deploy
run: |
gcloud run deploy ${SERVICE} --image ${HOSTNAME}/${PROJECT}/${SERVICE} --allow-unauthenticated
PREVIEW_URL=$(gcloud run services describe ${SERVICE} --format 'value(status.url)')
gcloud run services update ${SERVICE} --set-env-vars BASE_URL=${PREVIEW_URL}
# Notify to Statuses
- name: Notify
run: |
PREVIEW_URL=$(gcloud run services describe ${SERVICE} --format 'value(status.url)')
curl -X POST \
--url ${{ github.event.pull_request._links.statuses.href }} \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-d "{
\"state\": \"success\",
\"target_url\": \"${PREVIEW_URL}\",
\"description\": \"Deploy preview ready!\",
\"context\": \"deploy/preview\"
}"
cleanup-preview:
name: Cleanup the Preview
if: github.event.action == 'closed'
runs-on: ubuntu-latest
steps:
# Setup gcloud CLI
- uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
with:
version: '274.0.0'
service_account_key: ${{ secrets.GCP_KEY }}

# Configure gcloud
- run: |
gcloud config set project ${PROJECT}
gcloud config set run/platform managed
gcloud config set run/region ${REGION}
gcloud auth configure-docker
- name: Delete the Cloud Run Service
run: gcloud --quiet run services delete ${SERVICE}

- name: Delete the Docker image in GCR
run: gcloud container images delete ${HOSTNAME}/${PROJECT}/${SERVICE}
42 changes: 42 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Go
on: [push]
jobs:

build:
name: Lint, Test, Build
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- windows-latest
- macOS-latest
goversion:
- 1.14
steps:

- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.goversion }}
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v1

- name: setup env
run: |
echo "::set-env name=GOPATH::$(go env GOPATH)"
echo "::add-path::$(go env GOPATH)/bin"
- name: Setup
run: make setup

- name: Lint
run: make lint

- name: Test
run: make test

- name: Build
run: make build
33 changes: 33 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: release
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Unshallow
run: git fetch --prune --unshallow

- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.14

- name: setup env
run: |
echo "::set-env name=GOPATH::$(go env GOPATH)"
echo "::add-path::$(go env GOPATH)/bin"
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v1
with:
version: latest
args: release --rm-dist
key: ${{ secrets.YOUR_PRIVATE_KEY }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea/
vendor/
registry/wire_gen.go
28 changes: 28 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
before:
hooks:
- make setup
- git checkout -- go.mod
- git checkout -- go.sum
- make generate
builds:
- goos:
- darwin
- linux
- windows
env:
- CGO_ENABLED=0
- GO111MODULE=on
archives:
- format_overrides:
- goos: windows
format: zip
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM golang:1-buster AS builder
ENV GO111MODULE on
RUN mkdir /src
WORKDIR /src
COPY go.mod .
COPY go.sum .
RUN go mod download

COPY . /src
WORKDIR /src
RUN make setup
RUN make build

FROM alpine:3.11
RUN mkdir /lib64
RUN ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2
COPY --from=builder /src/cli-template /usr/local/bin
ENTRYPOINT ["/usr/local/bin/cli-template", "serve"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright © 2018 mpppk <niboshiporipori@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
51 changes: 51 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
SHELL = /bin/bash

.PHONY: setup
setup:
go get github.com/google/wire/cmd/wire
go get github.com/goreleaser/goreleaser

.PHONY: lint
lint: generate
go vet ./...
goreleaser check

.PHONY: test
test: generate
go test ./...

.PHONY: integration-test
integration-test:
go test -tags=integration ./...

.PHONY: coverage
coverage: generate
go test -race -coverprofile=coverage.txt -covermode=atomic ./...

.PHONY: codecov
codecov: coverage
bash <(curl -s https://codecov.io/bash)

.PHONY: wire
wire:
go generate -tags=wireinject ./...

.PHONY: generate
generate: wire
go generate ./...

.PHONY: build
build: generate
go build

.PHONY: cross-build-snapshot
cross-build:
goreleaser --rm-dist --snapshot

.PHONY: install
install:
go install

.PHONY: circleci
circleci:
circleci build -e GITHUB_TOKEN=$GITHUB_TOKEN
26 changes: 26 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: "{build}"

platform: x64

clone_folder: c:\gopath\src\github.com\mpppk\cli-template

environment:
GOPATH: c:\gopath
GO111MODULE: on

install:
- set PATH=%GOPATH%/bin;%PATH%
- echo %PATH%
- echo %GOPATH%
- git submodule update --init --recursive
- go version
- go env
- go get github.com/google/wire/cmd/wire
- go get -v -t -d ./...
- go generate -tags=wireinject ./...
- go vet ./...

build_script:
- go test -v ./...
- go build

10 changes: 10 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package cmd

import (
"github.com/spf13/afero"
"github.com/spf13/cobra"
)

type cmdGenerator func(fs afero.Fs) (*cobra.Command, error)

var cmdGenerators []cmdGenerator
3 changes: 3 additions & 0 deletions cmd/option/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package option

var DefaultStringValue = "__DEFAULT_STRING_VALUE__"

0 comments on commit e74e6ef

Please sign in to comment.