Skip to content

Commit

Permalink
wordchain v1.0.0 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
spkane committed Mar 31, 2021
1 parent 0eba4a7 commit cfdc9b2
Show file tree
Hide file tree
Showing 788 changed files with 330,209 additions and 70 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Dockerfile
.git
CHANGELOG
README.md
builds
wordchain
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
43 changes: 43 additions & 0 deletions .github/workflows/image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Build Container Image

on:
push:
branches:
- 'main'

jobs:
buildx:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
-
name: Available platforms
run: echo ${{ steps.buildx.outputs.platforms }}
-
name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
tags: superorbital/wordchain:latest
-
name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
wordchain
.DS_Store
/wordchain
builds
14 changes: 14 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is loosely based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

## [1.0.0] - 2021-03-30
### Added
- Added command line support
- Added micro service (listener) mode
- Confirmed basic Go Library functionality
- More details in the README

22 changes: 14 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
FROM golang:1.16-alpine3.13 AS build
ARG ARCH=
FROM ${ARCH}golang:1.16-alpine3.13 AS build

RUN apk --no-cache add \
bash \
gcc \
musl-dev \
openssl
RUN mkdir -p /go/src/github.com/superorbital/wordchain
WORKDIR /go/src/github.com/superorbital/wordchain
ADD . /go/src/github.com/superorbital/wordchain

ENV CGO_ENABLED=0

COPY . /build
WORKDIR /build

RUN go get github.com/markbates/pkger/cmd/pkger && \
pkger -include /data/words.json && \
go build -mod=vendor --ldflags '-linkmode external -extldflags "-static"' .
go build .

FROM alpine:3.13 AS deploy
FROM ${ARCH}alpine:3.13 AS deploy

WORKDIR /
COPY --from=build /go/src/github.com/superorbital/wordchain/wordchain /
COPY --from=build /build/wordchain /

USER 500
EXPOSE 8080

ENTRYPOINT ["/wordchain"]
CMD ["random"]
CMD ["listen"]

53 changes: 44 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,37 @@

## Development

```go
go get github.com/markbates/pkger/cmd/pkger
pkger -include /data/words.json
go build .
```shell
$ go get github.com/markbates/pkger/cmd/pkger
$ pkger -include /data/words.json
# Install go-swagger
# https://goswagger.io/install.html
$ swagger generate server -f ./swagger.yaml --exclude-main
$ go mod vendor
$ go build .
```

## Releasing

* Update the Version in `cmd/root.go`

```shell
go get github.com/mitchellh/gox
gox -osarch='!darwin/386' -output './builds/wordchain_{{.OS}}_{{.Arch}}'
$ go get github.com/mitchellh/gox
$ gox -osarch='!darwin/386' -output './builds/wordchain_{{.OS}}_{{.Arch}}'
```

* Create a release in Github with the resulting binaries.

### Docker Release

* See: https://www.docker.com/blog/multi-arch-build-and-images-the-simple-way/

```shell
$ docker build -t superorbital/wordchain:${VERISON} .
$ docker push superorbital/wordchain:${VERISON}
$ swagger generate server -f ./swagger.yaml --exclude-main
$ docker buildx build \
--push \
--platform linux/arm/v7,linux/arm64/v8,linux/amd64 \
--tag superorbital/wordchain:${VERISON} .
```

## Usage
Expand Down Expand Up @@ -91,10 +100,29 @@ hello+odd+pad+goodbye
$ ./wordchain export > internal-word-list.json
```

### Microservice

```shell
$ wordchain listen --port 8080
2021/03/30 11:32:02 Serving word chains at http://[::]:8080

$ curl -X POST -d '{}' -H 'Content-Type: application/json' http://127.0.0.1:8080/v1/random
"{\"chain\":\"quack-bayou\"}"

$ curl -X POST -d '{"length": 3}' -H 'Content-Type: application/json' http://127.0.0.1:8080/v1/random
"{\"chain\":\"odd-toy\"}"

$ curl -X POST -d '{"divider": "_", "length": 3, "prepend": "hello", "postpend": "adios", "seed": "deterministic" }' -H 'Content-Type: application/json' http://127.0.0.1:8080/v1/random
"{\"chain\":\"hello_bad_ace_adios\"}"
```

### Docker

```shell
$ docker run superorbital/wordchain:latest
2021/03/30 20:35:07 Serving word chains at http://[::]:8080

$ docker run superorbital/wordchain:latest random
alpha-drink

$ docker run superorbital/wordchain:latest random -l 3
Expand Down Expand Up @@ -155,8 +183,15 @@ It will expect a data file of words to exist. You can either create a valid JSON
}
```

## Ideas
## TODO & Ideas

* Add tests
* Make listener use defaults passed in at the command line
* Add swagger into Dockerfile (multi-arch)
* Add automated docker buildx support for releases
* create official release on github (with script ideally)
* Add a small demo video and maybe even a one page tool github page at `wordchain.superorbital.io`
* Add HTTPS and Unix socket support to listener mode.
* Add viper config file w/ env support
* Allow for a range of word length (like 3-5 characters)
* extend list (versus completely replace)
Expand Down
49 changes: 49 additions & 0 deletions cmd/listen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
Copyright © 2021 SuperOrbital, LLC <[email protected]>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
"github.com/spf13/cobra"
"github.com/superorbital/wordchain/listen"
types "github.com/superorbital/wordchain/types"
)

var settings types.Listener

// listenCmd represents the listen command
var listenCmd = &cobra.Command{
Use: "listen",
Short: "Listen on a port for requests to generate wordchains",
Long: `This launches the application as a long running service that will respond to a JSON request with a wordchain`,
Run: func(cmd *cobra.Command, args []string) {
listen.Listen(prefs, settings)
},
}

func init() {
rootCmd.AddCommand(listenCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// listenCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// listenCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
listenCmd.Flags().IntVar(&settings.Port, "port", 8080, "Port to bind to")
}
9 changes: 8 additions & 1 deletion cmd/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ limitations under the License.
package cmd

import (
"fmt"
"log"

"github.com/spf13/cobra"
"github.com/superorbital/wordchain/words"
)
Expand All @@ -26,7 +29,11 @@ var randomCmd = &cobra.Command{
Short: "Generates a random word chain",
Long: `Generates a random word chain with support for customization.`,
Run: func(cmd *cobra.Command, args []string) {
words.Random(prefs)
chain, err := words.Random(prefs)
if err != nil {
log.Fatal(err)
}
fmt.Println(chain)
},
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func init() {
// rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file (default is $HOME/.wordchain.yaml)")
rootCmd.PersistentFlags().StringVarP(&prefs.Divider, "divider", "d", "-", "The divider to use between words")
rootCmd.PersistentFlags().StringVarP(&prefs.WordFile, "json", "j", "", "word list json file")
rootCmd.PersistentFlags().Int8VarP(&prefs.Length, "length", "l", 5, "The length of words to use")
rootCmd.PersistentFlags().Int64VarP(&prefs.Length, "length", "l", 5, "The length of words to use")
rootCmd.PersistentFlags().StringVarP(&prefs.Postpend, "postpend", "o", "", "string to postpend to the output")
rootCmd.PersistentFlags().StringVarP(&prefs.Prepend, "prepend", "r", "", "string to prepend to the output")
rootCmd.PersistentFlags().StringSliceVarP(&prefs.Type, "type", "t", []string{"adjective", "noun"}, "Comma seperated list of word types")
Expand Down
13 changes: 13 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ module github.com/superorbital/wordchain
go 1.16

require (
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
github.com/go-openapi/errors v0.20.0
github.com/go-openapi/loads v0.20.2
github.com/go-openapi/runtime v0.19.27
github.com/go-openapi/spec v0.20.3
github.com/go-openapi/strfmt v0.20.0
github.com/go-openapi/swag v0.19.14
github.com/go-openapi/validate v0.20.2
github.com/gobuffalo/here v0.6.2 // indirect
github.com/jessevdk/go-flags v1.5.0
github.com/mailru/easyjson v0.7.7 // indirect
github.com/markbates/pkger v0.17.1
github.com/spf13/cobra v1.1.3
go.mongodb.org/mongo-driver v1.5.0 // indirect
golang.org/x/net v0.0.0-20210323141857-08027d57d8cf
)
Loading

0 comments on commit cfdc9b2

Please sign in to comment.