Skip to content

Commit

Permalink
Merge pull request #43 from qaware/32-provide-linux-packages-for-prot…
Browse files Browse the repository at this point in the history
…ocurl

32 provide linux packages for protocurl
  • Loading branch information
qa-swaneet-sahoo authored Apr 26, 2022
2 parents ae727b2 + 075bb7a commit 356d52d
Show file tree
Hide file tree
Showing 106 changed files with 384 additions and 50 deletions.
44 changes: 38 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ jobs:

post-release-test-windows:
runs-on: windows-latest
needs: [release]
needs: [ release ]
steps:
- uses: actions/checkout@v3

Expand Down Expand Up @@ -190,11 +190,11 @@ jobs:
- name: Test extracted release and global installation
run: |
$ErrorActionPreference = "Stop"
& ".\test\suite\native-tests.ps1" "./my-protocurl" ".exe"
& ".\test\suite\native-tests.ps1" "my-protocurl" ".exe" "localDirTests"
post-release-test-mac:
runs-on: macos-latest
needs: [release]
needs: [ release ]
steps:
- uses: actions/checkout@v3
- name: Setup
Expand All @@ -216,9 +216,9 @@ jobs:
sed "s/x86_64/amd64/g" |
sed "s/x86_32/386/g" |
sed "s/aarch_64/arm64/g")"
echo "arch: $ARCH"
echo "Arch: $ARCH"
gh release download v${{ github.event.inputs.version }} --pattern "*darwin*$ARCH*.zip"
echo "working dir after download"
echo "Working dir after Download"
ls
echo "Attempting to extract"
unzip *.zip -d my-protocurl
Expand All @@ -232,4 +232,36 @@ jobs:
- name: Test extracted release and global installation
run: |
pwsh test/suite/native-tests.ps1 "./my-protocurl" ""
pwsh test/suite/native-tests.ps1 "my-protocurl" "" "localDirTests"
post-release-test-linux:
runs-on: ubuntu-latest
needs: [ release ]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-node@v3
with:
node-version: "17.7.2"

- name: Start test server
run: |
cd test
pwsh servers/native-start-server.ps1
- name: "Run tests for linux package formats: deb, apk"
run: |
ARCH="$(uname -m |
sed "s/x86_64/amd64/g" |
sed "s/x86_32/386/g" |
sed "s/aarch_64/arm64/g")"
URL_NO_EXT="https://github.com/qaware/protocurl/releases/download/v${{github.event.inputs.version}}/protocurl_${{github.event.inputs.version}}_linux_${ARCH}"
docker run --network host -v $PWD/test:/home/test alpine:latest sh -c \
"cd home; apk add --no-cache bash && bash ./test/suite/linux/install-test-remove.sh alpine .apk $URL_NO_EXT"
docker run --network host -v $PWD/test:/home/test debian:stable-slim bash -c \
"cd home; ./test/suite/linux/install-test-remove.sh debian .deb $URL_NO_EXT"
4 changes: 2 additions & 2 deletions EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ $ docker run -v "$PWD/test/proto:/proto" --network host qaware/protocurl \
-d ""
```

will produce no output and only show this error:
will produce no output, exit with a non-zero exitcode and only show this error:

```bash
Error: Request was unsuccessful. Received response status code outside of 2XX. Got: HTTP/1.1 404 Not Found
Expand Down Expand Up @@ -386,7 +386,7 @@ Total curl args:
=========================== Response Headers =========================== <<<
HTTP/1.1 200 OK
Content-Type: application/x-protobuf
Date: Sat, 23 Apr 2022 16:43:47 GMT
Date: Tue, 26 Apr 2022 22:44:45 GMT
Connection: keep-alive
Keep-Alive: timeout=5
Content-Length: 35
Expand Down
31 changes: 24 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,34 @@ human-readable text formats.
`protocurl` includes and uses a bundled `protoc` by default. It is recommended to install `curl` into PATH for
configurable http requests. Otherwise `protocurl` will use a simple non-configurable fallback http implementation.

#### Native CLI
### Native CLI

**Archive**

1. Download the latest release archive for your platform from https://github.com/qaware/protocurl/releases
2. Extract the archive into a folder, e.g. `/usr/local/protocurl`.
3. Add symlink to the binary in the folder. e.g. `ln -s /usr/local/protocurl/bin/protocurl /usr/local/bin/protocurl`
Or add the binary folder `/usr/local/protocurl/bin` to your system-wide path.
4. Test that it works via `protocurl -h`
2. Extract the archive into a folder, e.g. `/opt/protocurl`.
3. Add symlink to the binary in the folder. e.g. `ln -s /opt/protocurl/bin/protocurl /usr/bin/protocurl`
Or add the binary folder `/opt/protocurl/bin` to your system-wide path.
4. Test it via `protocurl -h`

**Debian .deb package**

1. Download the latest release `.deb` for your architecture from https://github.com/qaware/protocurl/releases
2. Install dependency curl: `sudo apt install curl`
3. Install `sudo dpkg -i <downloaded-release>.deb`
4. Test it via `protocurl -h`

**Alpine .apt package**

1. Download the latest release `.apk` for your architecture from https://github.com/qaware/protocurl/releases
2. Install dependencies curl and gcompat: `sudo apk add curl gcompat`
3. Install `sudo apk add --allow-untrusted <downloaded-release>.apk`
4. Test it via `protocurl -h`

#### Docker
### Docker

Simply run `docker run -v "/path/to/proto/files:/proto" qaware/protocurl <args>`. See [Quick Start](#quick-start) for how to use.
Simply run `docker run -v "/path/to/proto/files:/proto" qaware/protocurl <args>`. See [Quick Start](#quick-start) for
how to use.

## Quick Start

Expand Down
11 changes: 9 additions & 2 deletions TESTS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# Tests

There are two tests. The docker-containerized tests and multi-platform native tests (running on windows, macos, etc.).
There are three types of tests. The docker-containerized tests, multi-platform native archive tests (running on windows,
macos, etc.)
and multi-platform native package tests.

The containerized tests do much of the heavy lifting in ensuring correctness - whereas the native tests ensure that the
basic functionality work multi-platform and contains regression tests for OS-specific behavior.

The native tests extract the release archive and the release packages (e.g. .deb, .apk) and run basic tests.

## Containerized Tests

The tests are run automatically via GitHub Actions [here](.github/workflows/test.yml). Run them
Expand Down Expand Up @@ -90,7 +95,9 @@ jobs are named `post-release-test-<OS>`. After setting up the machine, they star
via [test/servers/native-start-server.ps1](test/servers/native-start-server.ps1) and run the tests.

The output is not tested rigorously like the containerized tests. Only the successful exit is tested implicitly as the
Powershell is set to stop on the first error via `$ErrorActionPreference = "Stop"`.
Powershell is set to stop on the first error via `$ErrorActionPreference = "Stop"` and `$LASTEXITCODE`.

On linux the release packages are tested inside a container.

## Example Containerized Tests

Expand Down
2 changes: 1 addition & 1 deletion doc/template.EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ With `-q` all errors are written to stderr making it ideal for piping in scripts
___EXAMPLE_OUTPUT_ONLY_WITH_ERR_1___
```

will produce no output and only show this error:
will produce no output, exit with a non-zero exitcode and only show this error:

```bash
___EXAMPLE_OUTPUT_ONLY_WITH_ERR_2___
Expand Down
31 changes: 24 additions & 7 deletions doc/template.README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,34 @@ human-readable text formats.
`protocurl` includes and uses a bundled `protoc` by default. It is recommended to install `curl` into PATH for
configurable http requests. Otherwise `protocurl` will use a simple non-configurable fallback http implementation.

#### Native CLI
### Native CLI

**Archive**

1. Download the latest release archive for your platform from https://github.com/qaware/protocurl/releases
2. Extract the archive into a folder, e.g. `/usr/local/protocurl`.
3. Add symlink to the binary in the folder. e.g. `ln -s /usr/local/protocurl/bin/protocurl /usr/local/bin/protocurl`
Or add the binary folder `/usr/local/protocurl/bin` to your system-wide path.
4. Test that it works via `protocurl -h`
2. Extract the archive into a folder, e.g. `/opt/protocurl`.
3. Add symlink to the binary in the folder. e.g. `ln -s /opt/protocurl/bin/protocurl /usr/bin/protocurl`
Or add the binary folder `/opt/protocurl/bin` to your system-wide path.
4. Test it via `protocurl -h`

**Debian .deb package**

1. Download the latest release `.deb` for your architecture from https://github.com/qaware/protocurl/releases
2. Install dependency curl: `sudo apt install curl`
3. Install `sudo dpkg -i <downloaded-release>.deb`
4. Test it via `protocurl -h`

**Alpine .apt package**

1. Download the latest release `.apk` for your architecture from https://github.com/qaware/protocurl/releases
2. Install dependencies curl and gcompat: `sudo apk add curl gcompat`
3. Install `sudo apk add --allow-untrusted <downloaded-release>.apk`
4. Test it via `protocurl -h`

#### Docker
### Docker

Simply run `docker run -v "/path/to/proto/files:/proto" qaware/protocurl <args>`. See [Quick Start](#quick-start) for how to use.
Simply run `docker run -v "/path/to/proto/files:/proto" qaware/protocurl <args>`. See [Quick Start](#quick-start) for
how to use.

## Quick Start

Expand Down
7 changes: 6 additions & 1 deletion release/30-build-go-archive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ goreleaser check

echo "Using GORELEASER_CURRENT_TAG=$GORELEASER_CURRENT_TAG, GORELEASER_PREVIOUS_TAG=$GORELEASER_PREVIOUS_TAG"

goreleaser release --rm-dist
GORELEASER_ARGS=""
if [[ "$SNAPSHOT" == "true" ]]; then
GORELEASER_ARGS="--skip-announce"
fi

goreleaser release --rm-dist $GORELEASER_ARGS

# Alternate commands when testing release process locally
# goreleaser release --snapshot --rm-dist # DEV
Expand Down
2 changes: 2 additions & 0 deletions release/source.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
set -e

# PRECONDITION: git fetch origin --tags

source ./release/0-get-latest-dependencies-versions.sh

# should be one of 386, amd64 and arm64
Expand Down
2 changes: 2 additions & 0 deletions src/protocurl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"encoding/hex"
"fmt"
"os"

"github.com/spf13/cobra"
"google.golang.org/protobuf/reflect/protoregistry"
Expand Down Expand Up @@ -45,6 +46,7 @@ func main() {
defer func() {
if err := recover(); err != nil {
PrintError(fmt.Errorf("%v", err))
os.Exit(1)
}
}()
PanicOnError(rootCmd.Execute())
Expand Down
53 changes: 52 additions & 1 deletion template.goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Documentation at https://goreleaser.com

# This file is a template and expressions such as __PROTOC_VERSION__ are replaced
# with envrionment variables such as $PROTOC_VERSION before usage.
# with environment variables such as $PROTOC_VERSION before usage.

# https://goreleaser.com/customization/build/
builds:
Expand All @@ -23,6 +23,7 @@ builds:
archives:
- format: zip
files:
# NOTE: These files are listed again in the packages below. Keep them synced!
# binary is added implicitly
- README.md
- LICENSE.md
Expand All @@ -34,6 +35,56 @@ archives:
dst: 'protocurl-internal/include/google/protobuf'
strip_parent: true

# Linux packages
nfpms:
- package_name: protocurl
description: |-
protoCURL is cURL for Protobuf:
The command-line tool for interacting with Protobuf over
HTTP REST endpoints using human-readable text formats.
homepage: https://github.com/qaware/protocurl
license: MIT
maintainer: GollyTicker <[email protected]>
priority: extra

formats:
- apk
- deb
dependencies:
- curl
suggests:
- curl

overrides:
# protoc is compiled against glibc whereas alpine uses musl.
# See: https://stackoverflow.com/a/64447927
apk:
dependencies:
- curl
- gcompat

# adds the ./bin/protocurl
bindir: /opt/protocurl

# GoReleaser will automatically add the binaries.
contents:
- src: /opt/protocurl/bin/protocurl
dst: /usr/bin/protocurl
type: "symlink"

# NOTE: These files are listed again in the archives above. Keep them synced!
# binary is added implicitly
- src: README.md
dst: /opt/protocurl/README.md
- src: LICENSE.md
dst: /opt/protocurl/LICENSE.md
# copy protoc binaries and their .proto files previously downloaded
- src: 'release/tmp/protoc-__PROTO_VERSION__-{{ .Os }}-{{ .Arch }}/bin'
dst: '/opt/protocurl/protocurl-internal/bin'
- src: 'release/tmp/protoc-__PROTO_VERSION__-{{ .Os }}-{{ .Arch }}/include/google/protobuf'
dst: '/opt/protocurl/protocurl-internal/include/google/protobuf'

release:
# If set to auto, will mark the release as not ready for production
# in case there is an indicator for this in the tag e.g. v1.0.0-rc1
Expand Down
3 changes: 2 additions & 1 deletion test/results/additional-curl-args-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ includeReason: true
=========================== Response Headers =========================== <<<
HTTP/1.1 200 OK
Content-Type: application/x-protobuf
Date: Sun, 17 Apr 2022 23:33:23 GMT
Date: Tue, 26 Apr 2022 22:34:28 GMT
Connection: keep-alive
Keep-Alive: timeout=5
Content-Length: 65
Expand All @@ -25,3 +25,4 @@ isHappyDay: true
reason: "Thursday is a Happy Day! ⭐"
formattedDate: "Thu, 13 Jan 2022 03:35:39 GMT"
######### STDERR #########
######### EXIT 0 #########
1 change: 1 addition & 0 deletions test/results/additional-curl-args-no-curl-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
Error: Both --curl and --no-curl are active.
I cannot use and not use curl.
Please check the supplied and implied arguments via -v.
######### EXIT 1 #########
5 changes: 3 additions & 2 deletions test/results/additional-curl-args-verbose-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ Total curl args:
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-Type: application/x-protobuf
< Date: Sat, 23 Apr 2022 16:37:08 GMT
< Date: Tue, 26 Apr 2022 22:34:37 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5
< Content-Length: 65
Expand All @@ -287,7 +287,7 @@ Total curl args:
=========================== Response Headers =========================== <<<
HTTP/1.1 200 OK
Content-Type: application/x-protobuf
Date: Sat, 23 Apr 2022 16:37:08 GMT
Date: Tue, 26 Apr 2022 22:34:37 GMT
Connection: keep-alive
Keep-Alive: timeout=5
Content-Length: 65
Expand All @@ -304,3 +304,4 @@ isHappyDay: true
reason: "Thursday is a Happy Day! ⭐"
formattedDate: "Thu, 13 Jan 2022 03:35:39 GMT"
######### STDERR #########
######### EXIT 0 #########
3 changes: 2 additions & 1 deletion test/results/display-binary-and-headers-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ includeReason: true
=========================== Response Headers =========================== <<<
HTTP/1.1 200 OK
Content-Type: application/x-protobuf
Date: Sun, 17 Apr 2022 23:33:23 GMT
Date: Tue, 26 Apr 2022 22:34:21 GMT
Connection: keep-alive
Keep-Alive: timeout=5
Content-Length: 65
Expand All @@ -25,3 +25,4 @@ isHappyDay: true
reason: "Thursday is a Happy Day! ⭐"
formattedDate: "Thu, 13 Jan 2022 03:35:39 GMT"
######### STDERR #########
######### EXIT 0 #########
3 changes: 2 additions & 1 deletion test/results/display-binary-and-headers-no-curl-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ HTTP/1.1 200 OK
Content-Length: 65
Connection: keep-alive
Content-Type: application/x-protobuf
Date: Sun, 17 Apr 2022 23:33:23 GMT
Date: Tue, 26 Apr 2022 22:34:24 GMT
Keep-Alive: timeout=5
=========================== Response Binary =========================== <<<
00000000 08 01 12 1c 54 68 75 72 73 64 61 79 20 69 73 20 |....Thursday is |
Expand All @@ -25,3 +25,4 @@ isHappyDay: true
reason: "Thursday is a Happy Day! ⭐"
formattedDate: "Thu, 13 Jan 2022 03:35:39 GMT"
######### STDERR #########
######### EXIT 0 #########
1 change: 1 addition & 0 deletions test/results/echo-empty-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
=========================== Response Text =========================== <<<

######### STDERR #########
######### EXIT 0 #########
Loading

0 comments on commit 356d52d

Please sign in to comment.