diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..e33edcb --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,30 @@ +name: goreleaser +on: + # Trigger the workflow on push or pull request, + # but only if a semver tag is created. + push: + tags: + - v*.*.* +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v1 + - + name: Set up Go + uses: actions/setup-go@v1 + with: + go-version: 1.13.x + - + name: Login to DockerHub Registry + run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin + - + name: Run GoReleaser + uses: goreleaser/goreleaser-action@v1 + with: + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4373d24 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +pfxsigner +dist/ +props.json \ No newline at end of file diff --git a/.goreleaser.yml b/.goreleaser.yml index 5227136..68aaf8c 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -11,9 +11,24 @@ before: hooks: - make build -archive: - format: tar.gz - files: - - props.json.sample - - README.md - - LICENSE +archives: + - format: tar.gz + files: + - props.json.sample + - README.md + - LICENSE + +dockers: + - + goos: linux + goarch: amd64 + goarm: '' + binaries: + - pfxsigner + image_templates: + - "kailashnadh/pfxsigner:latest" + - "kailashnadh/pfxsigner:{{ .Tag }}" + skip_push: false + dockerfile: Dockerfile + extra_files: + - props.json.sample \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bf0ad14 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ +FROM ubuntu:latest AS deploy +WORKDIR /app +COPY pfxsigner . +COPY props.json.sample . +ENTRYPOINT [ "./pfxsigner" ] diff --git a/Makefile b/Makefile index 281234d..9c9dbaf 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +.PHONY : build test clean + LAST_COMMIT := $(shell git rev-parse --short HEAD) LAST_COMMIT_DATE := $(shell git show -s --format=%ci ${LAST_COMMIT}) VERSION := $(shell git describe --abbrev=1) @@ -5,11 +7,9 @@ BUILDSTR := ${VERSION} (build "\\\#"${LAST_COMMIT} $(shell date '+%Y-%m-%d %H:%M BIN := pfxsigner -.PHONY: build build: go build -o ${BIN} -ldflags="-s -w -X 'main.buildString=${BUILDSTR}'" -.PHONY: test test: go test ./... diff --git a/README.md b/README.md index c9df8b3..90b92f7 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ In the server mode, pfxsigner exposes an HTTP API to which a PDF file and signat ```shell # Start the server -./pfxsigner -pfx-file cert.pfx -props-file "props.json" server +./pfxsigner -pfx-file cert.pfx -pfx-password password -props-file "props.json" server ``` ```shell @@ -30,6 +30,18 @@ REQ=$(cat props.json.sample) curl -F "props=$REQ" -F 'file=@./test.pdf' -o './test-signed.pdf' localhost:8000/document ``` +## Docker + +You can use the [official]() Docker image to run `pfxsigner`. + +**NOTE**: You'll need to mount `cert.pfx` and `props.json` from a directory available on host machine to a directory inside container. You can do that by passing `-v :` while launching the container. + +```shell +# For example `./data` contains `cert.pfx` and `props.json`. +export PFX_PASSWORD=mysecurepass +docker run -it -p 8000:8000 -v "$PWD"/data:/data kailashnadh/pfxsigner:latest -pfx-file /data/cert.pfx -pfx-password $PFX_PASSWORD -props-file /data/props.json server +``` + ### API The API endpoint is `:8000/document`. It accepts a POST request (multipart/form-data) with the following fields. diff --git a/server.go b/server.go index 26f5b34..f86bd64 100644 --- a/server.go +++ b/server.go @@ -19,6 +19,8 @@ type httpResp struct { // initServer initializes CLI mode. func initServer(c *cli.Context) error { r := chi.NewRouter() + r.Get("/", handleIndex) + r.Get("/health", handleHealthCheck) r.Post("/document", handleDocument) // HTTP Server. @@ -36,6 +38,18 @@ func initServer(c *cli.Context) error { return nil } +// handleIndex is default index handler. +func handleIndex(w http.ResponseWriter, r *http.Request) { + sendResponse(w, "Welcome to pfxsigner. Send a request to /document for document signing.") + return +} + +// handleHealthCheck handles healthcheck request to check if service is available or not. +func handleHealthCheck(w http.ResponseWriter, r *http.Request) { + sendResponse(w, "healthy") + return +} + // handleDocument handles an HTTP document signing request. func handleDocument(w http.ResponseWriter, r *http.Request) { // Read the JSON request payload from the 'request' field.