Skip to content

Commit

Permalink
New release (#140)
Browse files Browse the repository at this point in the history
* Disable live-server tests by default

- They will always be run by our CI
- Also update and fix example in README.

* Update examples and add them to build

- Also drop support for GHC 8.2.2

* Bump up version for new release
  • Loading branch information
donatello authored Jan 2, 2020
1 parent c31030b commit d2a78df
Show file tree
Hide file tree
Showing 29 changed files with 335 additions and 239 deletions.
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ matrix:
include:

# Cabal
- ghc: 8.2.2
- ghc: 8.4.4
- ghc: 8.6.5
- ghc: 8.8.1
Expand All @@ -40,22 +39,22 @@ install:
ghc --version
cabal --version
cabal new-update
cabal new-build --enable-tests --enable-benchmarks
cabal new-build --enable-tests --enable-benchmarks -fexamples
else
# install stack
curl -sSL https://get.haskellstack.org/ | sh
# build project with stack
stack --version
stack build --system-ghc --test --bench --no-run-tests --no-run-benchmarks
stack build --system-ghc --test --bench --no-run-tests --no-run-benchmarks --flag minio-hs:examples
fi
script:
- |
if [ -z "$STACK_YAML" ]; then
MINIO_LOCAL=1 MINIO_SECURE=1 cabal new-test --enable-tests
MINIO_LOCAL=1 MINIO_SECURE=1 cabal new-test --enable-tests -flive-test
else
MINIO_LOCAL=1 MINIO_SECURE=1 stack test --system-ghc
MINIO_LOCAL=1 MINIO_SECURE=1 stack test --system-ghc --flag minio-hs:live-test
fi
notifications:
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
==========

## Version 1.5.2

* Fix region `us-west-2` for AWS S3 (#139)
* Build examples in CI
* Disable live-server tests by default, but run them in CI
* Drop support for GHC 8.2.x

## Version 1.5.1

* Add support for GHC 8.8
Expand Down
96 changes: 71 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,42 @@ The MinIO Haskell Client SDK provides simple APIs to access [MinIO](https://min.

## Installation

```sh
git clone https://github.com/minio/minio-hs.git
### Add to your project

cd minio-hs/
Simply add `minio-hs` to your project's `.cabal` dependencies section or if you are using hpack, to your `package.yaml` file as usual.

stack install
```
### Try it out directly with `ghci`

Tests can be run with:
From your home folder or any non-haskell project directory, just run:

```sh

stack test
stack install minio-hs

```

A section of the tests use the remote MinIO Play server at
`https://play.min.io` by default. For library development,
using this remote server maybe slow. To run the tests against a
locally running MinIO live server at `http://localhost:9000`, just set
the environment `MINIO_LOCAL` to any value (and unset it to switch
back to Play).

Documentation can be locally built with:
Then start an interpreter session and browse the available APIs with:

```sh

stack haddock

$ stack ghci
> :browse Network.Minio
```

## Quick-Start Example - File Uploader
## Examples

The [examples](https://github.com/minio/minio-hs/tree/master/examples) folder contains many examples that you can try out and use to learn and to help with developing your own projects.

### Quick-Start Example - File Uploader

This example program connects to a MinIO object storage server, makes a bucket on the server and then uploads a file to the bucket.

We will use the MinIO server running at https://play.min.io in this example. Feel free to use this service for testing and development. Access credentials are present in the library and are open to the public.

### FileUploader.hs
``` haskell
#!/usr/bin/env stack
-- stack --resolver lts-11.1 runghc --package minio-hs --package optparse-applicative --package filepath
-- stack --resolver lts-14.11 runghc --package minio-hs --package optparse-applicative --package filepath

--
-- MinIO Haskell SDK, (C) 2017-2019 MinIO, Inc.
Expand Down Expand Up @@ -106,16 +105,19 @@ main = do
res <- runMinio minioPlayCI $ do
-- Make a bucket; catch bucket already exists exception if thrown.
bErr <- try $ makeBucket bucket Nothing

-- If the bucket already exists, we would get a specific
-- `ServiceErr` exception thrown.
case bErr of
Left (MErrService BucketAlreadyOwnedByYou) -> return ()
Left e -> throwIO e
Right _ -> return ()
Left BucketAlreadyOwnedByYou -> return ()
Left e -> throwIO e
Right _ -> return ()

-- Upload filepath to bucket; object is derived from filepath.
fPutObject bucket object filepath def
-- Upload filepath to bucket; object name is derived from filepath.
fPutObject bucket object filepath defaultPutObjectOptions

case res of
Left e -> putStrLn $ "file upload failed due to " ++ (show e)
Left e -> putStrLn $ "file upload failed due to " ++ show e
Right () -> putStrLn "file upload succeeded."
```

Expand All @@ -129,3 +131,47 @@ main = do
## Contribute

[Contributors Guide](https://github.com/minio/minio-hs/blob/master/CONTRIBUTING.md)

### Development

To setup:

```sh
git clone https://github.com/minio/minio-hs.git

cd minio-hs/

stack install
```

Tests can be run with:

```sh

stack test

```

A section of the tests use the remote MinIO Play server at `https://play.min.io` by default. For library development, using this remote server maybe slow. To run the tests against a locally running MinIO live server at `http://localhost:9000`, just set the environment `MINIO_LOCAL` to any value (and unset it to switch back to Play).

To run the live server tests, set a build flag as shown below:

```sh

stack test --flag minio-hs:live-test

# OR against a local MinIO server with:

MINIO_LOCAL=1 stack test --flag minio-hs:live-test

```

The configured CI system always runs both test-suites for every change.

Documentation can be locally built with:

```sh

stack haddock

```
2 changes: 1 addition & 1 deletion examples/BucketExists.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env stack
-- stack --resolver lts-11.1 runghc --package minio-hs
-- stack --resolver lts-14.11 runghc --package minio-hs

--
-- MinIO Haskell SDK, (C) 2017, 2018 MinIO, Inc.
Expand Down
19 changes: 10 additions & 9 deletions examples/CopyObject.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env stack
-- stack --resolver lts-11.1 runghc --package minio-hs
-- stack --resolver lts-14.11 runghc --package minio-hs

--
-- MinIO Haskell SDK, (C) 2017, 2018 MinIO, Inc.
Expand All @@ -20,8 +20,7 @@
{-# LANGUAGE OverloadedStrings #-}
import Network.Minio

import Control.Monad.Catch (catchIf)
import Prelude
import UnliftIO.Exception (catch, throwIO)

-- | The following example uses minio's play server at
-- https://play.min.io. The endpoint and associated
Expand All @@ -30,9 +29,6 @@ import Prelude
-- > minioPlayCI :: ConnectInfo
--

ignoreMinioErr :: ServiceErr -> Minio ()
ignoreMinioErr = return . const ()

main :: IO ()
main = do
let
Expand All @@ -43,13 +39,18 @@ main = do

res1 <- runMinio minioPlayCI $ do
-- 1. Make a bucket; Catch BucketAlreadyOwnedByYou exception.
catchIf (== BucketAlreadyOwnedByYou) (makeBucket bucket Nothing) ignoreMinioErr
catch (makeBucket bucket Nothing) (
\e -> case e of
BucketAlreadyOwnedByYou -> return ()
_ -> throwIO e
)

-- 2. Upload a file to bucket/object.
fPutObject bucket object localFile
fPutObject bucket object localFile defaultPutObjectOptions

-- 3. Copy bucket/object to bucket/objectCopy.
copyObject def {dstBucket = bucket, dstObject = objectCopy} def { srcBucket = bucket , srcObject = object }
copyObject defaultDestinationInfo {dstBucket = bucket, dstObject = objectCopy}
defaultSourceInfo { srcBucket = bucket , srcObject = object }

case res1 of
Left e -> putStrLn $ "copyObject failed." ++ show e
Expand Down
11 changes: 6 additions & 5 deletions examples/FileUploader.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env stack
-- stack --resolver lts-11.1 runghc --package minio-hs --package optparse-applicative --package filepath
-- stack --resolver lts-14.11 runghc --package minio-hs --package optparse-applicative --package filepath

--
-- MinIO Haskell SDK, (C) 2017, 2018 MinIO, Inc.
Expand Down Expand Up @@ -43,6 +43,7 @@ fileNameArgs = strArgument
(metavar "FILENAME"
<> help "Name of file to upload to AWS S3 or a MinIO server")

cmdParser :: ParserInfo FilePath
cmdParser = info
(helper <*> fileNameArgs)
(fullDesc
Expand All @@ -62,12 +63,12 @@ main = do
-- Make a bucket; catch bucket already exists exception if thrown.
bErr <- try $ makeBucket bucket Nothing
case bErr of
Left (MErrService BucketAlreadyOwnedByYou) -> return ()
Left e -> throwIO e
Right _ -> return ()
Left BucketAlreadyOwnedByYou -> return ()
Left e -> throwIO e
Right _ -> return ()

-- Upload filepath to bucket; object is derived from filepath.
fPutObject bucket object filepath def
fPutObject bucket object filepath defaultPutObjectOptions

case res of
Left e -> putStrLn $ "file upload failed due to " ++ (show e)
Expand Down
4 changes: 2 additions & 2 deletions examples/GetConfig.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env stack
-- stack --resolver lts-11.1 runghc --package minio-hs
-- stack --resolver lts-14.11 runghc --package minio-hs

--
-- MinIO Haskell SDK, (C) 2017, 2018 MinIO, Inc.
Expand All @@ -25,6 +25,6 @@ import Prelude

main :: IO ()
main = do
res <- runMinio def $
res <- runMinio minioPlayCI $
getConfig
print res
6 changes: 3 additions & 3 deletions examples/GetObject.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env stack
-- stack --resolver lts-11.1 runghc --package minio-hs
-- stack --resolver lts-14.11 runghc --package minio-hs

--
-- MinIO Haskell SDK, (C) 2017, 2018 MinIO, Inc.
Expand Down Expand Up @@ -38,8 +38,8 @@ main = do
bucket = "my-bucket"
object = "my-object"
res <- runMinio minioPlayCI $ do
src <- getObject bucket object def
C.connect src $ CB.sinkFileCautious "/tmp/my-object"
src <- getObject bucket object defaultGetObjectOptions
C.connect (gorObjectStream src) $ CB.sinkFileCautious "/tmp/my-object"

case res of
Left e -> putStrLn $ "getObject failed." ++ (show e)
Expand Down
4 changes: 2 additions & 2 deletions examples/HeadObject.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env stack
-- stack --resolver lts-11.1 runghc --package minio-hs
-- stack --resolver lts-14.11 runghc --package minio-hs

--
-- MinIO Haskell SDK, (C) 2017, 2018 MinIO, Inc.
Expand Down Expand Up @@ -36,7 +36,7 @@ main = do
bucket = "test"
object = "passwd"
res <- runMinio minioPlayCI $
headObject bucket object
headObject bucket object []

case res of
Left e -> putStrLn $ "headObject failed." ++ show e
Expand Down
4 changes: 2 additions & 2 deletions examples/Heal.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env stack
-- stack --resolver lts-11.1 runghc --package minio-hs
-- stack --resolver lts-14.11 runghc --package minio-hs

--
-- MinIO Haskell SDK, (C) 2017, 2018 MinIO, Inc.
Expand All @@ -25,7 +25,7 @@ import Prelude

main :: IO ()
main = do
res <- runMinio def $
res <- runMinio minioPlayCI $
do
hsr <- startHeal Nothing Nothing HealOpts { hoRecursive = True
, hoDryRun = False
Expand Down
2 changes: 1 addition & 1 deletion examples/ListBuckets.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env stack
-- stack --resolver lts-11.1 runghc --package minio-hs
-- stack --resolver lts-14.11 runghc --package minio-hs

--
-- MinIO Haskell SDK, (C) 2017, 2018 MinIO, Inc.
Expand Down
2 changes: 1 addition & 1 deletion examples/ListIncompleteUploads.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env stack
-- stack --resolver lts-11.1 runghc --package minio-hs
-- stack --resolver lts-14.11 runghc --package minio-hs

--
-- MinIO Haskell SDK, (C) 2017, 2018 MinIO, Inc.
Expand Down
2 changes: 1 addition & 1 deletion examples/ListObjects.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env stack
-- stack --resolver lts-11.1 runghc --package minio-hs
-- stack --resolver lts-14.11 runghc --package minio-hs

--
-- MinIO Haskell SDK, (C) 2017, 2018 MinIO, Inc.
Expand Down
2 changes: 1 addition & 1 deletion examples/MakeBucket.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env stack
-- stack --resolver lts-11.1 runghc --package minio-hs
-- stack --resolver lts-14.11 runghc --package minio-hs

--
-- MinIO Haskell SDK, (C) 2017, 2018 MinIO, Inc.
Expand Down
8 changes: 4 additions & 4 deletions examples/PresignedGetObject.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env stack
-- stack --resolver lts-11.1 runghc --package minio-hs
-- stack --resolver lts-14.11 runghc --package minio-hs

--
-- MinIO Haskell SDK, (C) 2017, 2018 MinIO, Inc.
Expand Down Expand Up @@ -47,11 +47,11 @@ main = do

res <- runMinio minioPlayCI $ do
liftIO $ B.putStrLn "Upload a file that we will fetch with a presigned URL..."
putObject bucket object (CC.repeat "a") (Just kb15) def
putObject bucket object (CC.repeat "a") (Just kb15) defaultPutObjectOptions
liftIO $ putStrLn $ "Done. Object created at: my-bucket/my-object"

-- Extract Etag of uploaded object
oi <- statObject bucket object
oi <- statObject bucket object defaultGetObjectOptions
let etag = oiETag oi

-- Set header to add an if-match constraint - this makes sure
Expand All @@ -68,7 +68,7 @@ main = do

case res of
Left e -> putStrLn $ "presignedPutObject URL failed." ++ show e
Right (headers, etag, url) -> do
Right (headers, _, url) -> do

-- We generate a curl command to demonstrate usage of the signed
-- URL.
Expand Down
Loading

0 comments on commit d2a78df

Please sign in to comment.