Nixify CircleCI setup (#1535)

* package ghr
* add nix-based release scripts
* refactor CI based on nix tests and release scripts
* update stack version in circleci
* update makefile
* remove docker directory
* add Docker Hub description
* add README on docker
This commit is contained in:
Remo Rechkemmer
2020-05-25 11:27:35 -05:00
committed by GitHub
parent d4aba5cb08
commit 08186ea51c
20 changed files with 426 additions and 484 deletions
+101
View File
@@ -0,0 +1,101 @@
{ buildEnv
, curl
, envsubst
, ghr
, jq
, postgrest
, docker
, runCommand
, writeShellScriptBin
}:
let
# Version from the postgrest.cabal file (gotten with callCabal2nix).
version = postgrest.version;
# Set of files that will be published in the GitHub release.
releaseFiles =
runCommand "postgrest-release-files"
{ inherit postgrest version; }
''
set -euo pipefail
mkdir -p $out
tar cvJf "$out"/postgrest-v"$version"-linux-x64-static.tar.xz \
-C "$postgrest"/bin postgrest
'';
# Script for publishing a new release on GitHub.
github =
writeShellScriptBin "postgrest-release-github"
''
set -euo pipefail
changes="$(sed -n "1,/${version}/d;/## \[/q;p" ${../../CHANGELOG.md})"
${ghr}/bin/ghr \
-t "$GITHUB_TOKEN" \
-u "$GITHUB_USERNAME" \
-r "$GITHUB_REPONAME" \
-b "$changes" \
--replace v${version} \
${releaseFiles}
'';
# Script for publishing a new release on Docker Hub.
dockerHub =
writeShellScriptBin "postgrest-release-dockerhub"
''
set -euo pipefail
docker load -i ${docker.image}
docker tag postgrest:latest "$DOCKER_REPO"/postgrest:latest
docker tag postgrest:latest "$DOCKER_REPO"/postgrest:v${version}
docker push "$DOCKER_REPO"/postgrest:latest
docker push "$DOCKER_REPO"/postgrest:v${version}
'';
# Script for updating the repository description on Docker Hub.
dockerHubDescription =
let
description =
./docker-hub-description.md;
fullDescription =
./docker-hub-full-description.md;
in
writeShellScriptBin "postgrest-release-dockerhubdescription"
''
set -euo pipefail
# Login to Docker Hub and get a token.
token="$(
${curl}/bin/curl -sH "Content-Type: application/json" \
--data-urlencode "username=$DOCKER_USERNAME" \
--data-urlencode "password=$DOCKER_PASSWORD" \
"https://hub.docker.com/v2/users/login/" \
| ${jq}/bin/jq -r .token
)"
# Plug the default config file into the full description.
export DEFAULT_CONFIG="$(cat ${docker.config})"
fullDescription="$(${envsubst}/bin/envsubst < ${fullDescription})"
# Patch the full description.
responseCode="$(
${curl}/bin/curl -s --write-out %{response_code} --output /dev/null \
-H "Authorization: JWT $token" -X PATCH \
--data-urlencode description@${description} \
--data-urlencode "full_description=$fullDescription" \
"https://hub.docker.com/v2/repositories/$DOCKER_REPO/postgrest/"
)"
[ "$responseCode" -eq 200 ]
'';
in
buildEnv {
name = "postgrest-release";
paths = [ github dockerHub dockerHubDescription ];
}
+1
View File
@@ -0,0 +1 @@
REST API for any Postgres database
@@ -0,0 +1,33 @@
# PostgREST
[![Join the chat at https://gitter.im/begriffs/postgrest](https://img.shields.io/badge/gitter-join%20chat%20%E2%86%92-brightgreen.svg)](https://gitter.im/begriffs/postgrest)
[![Donate](https://img.shields.io/badge/Donate-Patreon-orange.svg?colorB=F96854)](https://www.patreon.com/postgrest)
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.me/postgrest)
[![Docs](https://img.shields.io/badge/docs-latest-brightgreen.svg?style=flat)](http://postgrest.org)
[![Build Status](https://circleci.com/gh/PostgREST/postgrest/tree/master.svg?style=shield)](https://circleci.com/gh/PostgREST/postgrest/tree/master)
PostgREST serves a fully RESTful API from any existing PostgreSQL database. It
provides a cleaner, more standards-compliant, faster API than you are likely to
write from scratch.
# Usage
To learn how to use this container, see the [PostgREST Docker
documentation](https://postgrest.com/en/stable/install.html#docker).
You can configure the PostgREST image by setting the enviroment variables used
in the default `/etc/postgrest.conf` file or overriding that file. This is the
default configuration file:
```
$DEFAULT_CONFIG
```
# How this image is built
The image is built from scratch using
[Nix](https://nixos.org/nixpkgs/manual/#sec-pkgs-dockerTools) instead of a
`Dockerfile`, which yields a higly secure and optimized image. This is also why
no commands are listed in the image history. See the [PostgREST
respository](https://github.com/PostgREST/postgrest/tree/master/nix/docker) for
details on the build process and how to inspect the image.