NicolasLopes7/shipthing

Run locally without acess aws s3

Opened this issue ยท 13 comments

Is it possible to use Minio in Docker Compose to emulate s3 and thus run it locally?

I've tried to implement it in docker compose, but I haven't tested it yet because I don't know how to automate the creation of the bucket.

version: '3.8'

services:
  redis:
    image: redis:6.2-alpine
    container_name: shipthing-redis
    restart: always
    ports:
    - '6379:6379'
    command: redis-server --loglevel warning --requirepass passwd


  minio:
    image: quay.io/minio/minio
    container_name: shipthing-minio-storage
    environment:
      MINIO_ROOT_USER: minioroot
      MINIO_ROOT_PASSWORD: secret-password
    ports:
      - '9000:9000'
      - '9001:9001'
    volumes:
      - minio-storage:/data
    command: server /data --console-address ':9001'
    healthcheck:
      test: ['CMD', 'curl', '-f', 'http://localhost:9000/minio/health/live']
      interval: 30s
      timeout: 20s
      retries: 3

volumes:
  minio-storage:

i think you need the minio cli to create the bucket inside the docker container

I found this on stack overflow and, in my tests, it works well.

version: '3.8'

services:

# redis instance

  minio:
    image: quay.io/minio/minio
    container_name: shipthing-minio-storage
    environment:
      MINIO_ROOT_USER: shipthing
      MINIO_ROOT_PASSWORD: secret-password
    ports:
      - '9000:9000'
      - '9001:9001'
    volumes:
      - minio-storage:/data
    command: server /data --console-address ':9001'
    healthcheck:
      test: ['CMD', 'curl', '-f', 'http://localhost:9000/minio/health/live']
      interval: 30s
      timeout: 20s
      retries: 3

  createbuckets:
    image: minio/mc
    depends_on:
      - minio
    entrypoint: >
      /bin/sh -c "
      /usr/bin/mc alias set shipthing http://minio:9000 shipthing secret-password;
      /usr/bin/mc mb shipthing/shipthing;
      /usr/bin/mc policy set public shipthing/shipthing;
      exit 0;
      "

volumes:
  minio-storage:

I'm researching how to connect to the local instance without breaking all the code, I found this solution:

.env

AWS_BUCKET_NAME="shipthing"
AWS_REGION="us-east-1"
AWS_ENDPOINT="http://localhost:9000"
REDIS_ADDR="localhost:6379"
REDIS_PASSWORD="passwd"

SECRET_KEY=""
ACCESS_KEY=""

config/config.go

func createAwsSession() (*session.Session, error) {
  sesh, err := session.NewSession(&aws.Config{
    Region: aws.String(os.Getenv("AWS_REGION")),
    Endpoint: aws.String(os.Getenv("AWS_ENDPOINT")),
    Credentials: credentials.NewStaticCredentials(
	    os.Getenv("ACCESS_KEY"),
	    os.Getenv("SECRET_KEY"),
	    "",
    ),
  })

however, after doing this, but when a request to /deploy the bucket is not found.

I'm not a golang dev ๐Ÿ˜…, so I don't know how to solve it.

Hey all, really good point! That will make it easier to test things and don't spend free tier accounts!

That said, I think we can might do is creating an Abstract S3 Service and implement two versions:

  • MockS3Service
  • S3Service

We can use the flag package to decide whether we should use. Anyone help to do this? I'm here to guidance and apologies for the delay on answering.

I think that we can also create a parameter on the makefile to tell if we want to use the mock version or the S3 one to test! The default can be the mock!

I'm also open for better suggestions!

Would Abstract S3 Service be a function to simulate the actions of MockS3Service or S3Service?

Would Abstract S3 Service be a function to simulate the actions of MockS3Service or S3Service?

@meiazero I think it would be an interface that would be implemented by MockS3Service and S3Service

Would Abstract S3 Service be a function to simulate the actions of MockS3Service or S3Service?

@meiazero I think it would be an interface that would be implemented by MockS3Service and S3Service

That's right @jotace1. Abstract S3 Service is just an interface to implementt both. Since s3 needs a aws sesssion and minio requires other stuff (still need to read it through).

So it would be one connecting to minio, and the other to s3!

is minio a must? I mean, there are others like localstack (I'm personally more familiar with localstack)

nope, if you wanna tackle it feel free to go with localstack :)

is minio a must? I mean, there are others like localstack (I'm personally more familiar with localstack)

I quickly read about localstack and it seems more pleasant to use than minio.
If you need any help, I'll be here ๐Ÿ˜„

yeah, I think using localstack can perhaps avoid the need for a mocked class. I'll work on that

yeah, I think using localstack can perhaps avoid the need for a mocked class. I'll work on that

tyvm! godspeed