2023-03-14 01:01:16 +00:00
|
|
|
import ./make-test-python.nix ({ pkgs, ... }:
|
|
|
|
let
|
2019-01-31 02:38:48 +00:00
|
|
|
accessKey = "BKIKJAA5BMMU2RHO6IBB";
|
|
|
|
secretKey = "V7f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12";
|
|
|
|
minioPythonScript = pkgs.writeScript "minio-test.py" ''
|
|
|
|
#! ${pkgs.python3.withPackages(ps: [ ps.minio ])}/bin/python
|
|
|
|
import io
|
|
|
|
import os
|
|
|
|
from minio import Minio
|
|
|
|
minioClient = Minio('localhost:9000',
|
|
|
|
access_key='${accessKey}',
|
|
|
|
secret_key='${secretKey}',
|
|
|
|
secure=False)
|
|
|
|
sio = io.BytesIO()
|
|
|
|
sio.write(b'Test from Python')
|
|
|
|
sio.seek(0, os.SEEK_END)
|
|
|
|
sio_len = sio.tell()
|
|
|
|
sio.seek(0)
|
|
|
|
minioClient.put_object('test-bucket', 'test.txt', sio, sio_len, content_type='text/plain')
|
|
|
|
'';
|
2023-03-14 01:00:43 +00:00
|
|
|
rootCredentialsFile = "/etc/nixos/minio-root-credentials";
|
2023-03-14 01:01:16 +00:00
|
|
|
credsPartial = pkgs.writeText "minio-credentials-partial" ''
|
2023-03-14 01:00:43 +00:00
|
|
|
MINIO_ROOT_USER=${accessKey}
|
|
|
|
'';
|
2023-03-14 01:01:16 +00:00
|
|
|
credsFull = pkgs.writeText "minio-credentials-full" ''
|
2023-03-14 01:00:43 +00:00
|
|
|
MINIO_ROOT_USER=${accessKey}
|
|
|
|
MINIO_ROOT_PASSWORD=${secretKey}
|
|
|
|
'';
|
2023-03-14 01:01:16 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
name = "minio";
|
|
|
|
meta = with pkgs.lib.maintainers; {
|
|
|
|
maintainers = [ bachp ];
|
|
|
|
};
|
2017-06-25 17:43:10 +01:00
|
|
|
|
2023-03-14 01:01:16 +00:00
|
|
|
nodes = {
|
|
|
|
machine = { pkgs, ... }: {
|
|
|
|
services.minio = {
|
|
|
|
enable = true;
|
|
|
|
inherit rootCredentialsFile;
|
|
|
|
};
|
|
|
|
environment.systemPackages = [ pkgs.minio-client ];
|
2017-10-01 19:58:28 +01:00
|
|
|
|
2023-03-14 01:01:16 +00:00
|
|
|
# Minio requires at least 1GiB of free disk space to run.
|
|
|
|
virtualisation.diskSize = 4 * 1024;
|
|
|
|
};
|
2017-07-07 23:11:44 +01:00
|
|
|
};
|
2017-06-25 17:43:10 +01:00
|
|
|
|
2023-03-14 01:01:16 +00:00
|
|
|
testScript = ''
|
|
|
|
import time
|
2023-03-14 01:00:43 +00:00
|
|
|
|
2023-03-14 01:01:16 +00:00
|
|
|
start_all()
|
|
|
|
# simulate manually editing root credentials file
|
|
|
|
machine.wait_for_unit("multi-user.target")
|
|
|
|
machine.copy_from_host("${credsPartial}", "${rootCredentialsFile}")
|
|
|
|
time.sleep(3)
|
|
|
|
machine.copy_from_host("${credsFull}", "${rootCredentialsFile}")
|
2023-03-14 01:00:43 +00:00
|
|
|
|
2023-03-14 01:01:16 +00:00
|
|
|
machine.wait_for_unit("minio.service")
|
|
|
|
machine.wait_for_open_port(9000)
|
2017-07-07 23:11:44 +01:00
|
|
|
|
2023-03-14 01:01:16 +00:00
|
|
|
# Create a test bucket on the server
|
|
|
|
machine.succeed(
|
|
|
|
"mc config host add minio http://localhost:9000 ${accessKey} ${secretKey} --api s3v4"
|
|
|
|
)
|
|
|
|
machine.succeed("mc mb minio/test-bucket")
|
|
|
|
machine.succeed("${minioPythonScript}")
|
|
|
|
assert "test-bucket" in machine.succeed("mc ls minio")
|
|
|
|
assert "Test from Python" in machine.succeed("mc cat minio/test-bucket/test.txt")
|
|
|
|
machine.shutdown()
|
|
|
|
'';
|
|
|
|
})
|