From e5de425e792d4d4501b353c606a6d53e36a4e546 Mon Sep 17 00:00:00 2001 From: Karan Sharma Date: Wed, 8 Jan 2020 16:20:20 +0530 Subject: [PATCH 1/5] feat: Add `.gitignore` to project --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitignore 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 From 925cd923f4f280ac853a9b76bd2a5b30e25c6c13 Mon Sep 17 00:00:00 2001 From: Karan Sharma Date: Wed, 8 Jan 2020 16:20:57 +0530 Subject: [PATCH 2/5] feat: Remove repetitive usage of `PHONY` in Makefile --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 ./... From 79156c7fedc90d0ff66965c17fb28912b179abcc Mon Sep 17 00:00:00 2001 From: Karan Sharma Date: Wed, 8 Jan 2020 16:22:37 +0530 Subject: [PATCH 3/5] feat: Add healthcheck and index handler in `server.go` --- server.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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. From 79b93681d380b817658374b30beac6f060e02779 Mon Sep 17 00:00:00 2001 From: Karan Sharma Date: Wed, 8 Jan 2020 16:23:02 +0530 Subject: [PATCH 4/5] feat: Dockerize pfxsigner --- .goreleaser.yml | 27 +++++++++++++++++++++------ Dockerfile | 5 +++++ README.md | 14 +++++++++++++- 3 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 Dockerfile 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/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. From 5608a6bebf109f9e483beb86f39e362a8cd9dac9 Mon Sep 17 00:00:00 2001 From: Karan Sharma Date: Wed, 8 Jan 2020 17:13:59 +0530 Subject: [PATCH 5/5] feat: Add github actions --- .github/workflows/main.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/main.yml 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