Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run locally without acess aws s3 #9

Open
eletroswing opened this issue Mar 2, 2024 · 13 comments
Open

Run locally without acess aws s3 #9

eletroswing opened this issue Mar 2, 2024 · 13 comments
Labels
good first issue Good for newcomers

Comments

@eletroswing
Copy link

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

@meiazero
Copy link
Contributor

meiazero commented Mar 2, 2024

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:

@eletroswing
Copy link
Author

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

@meiazero
Copy link
Contributor

meiazero commented Mar 3, 2024

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:

@meiazero
Copy link
Contributor

meiazero commented Mar 3, 2024

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.

@NicolasLopes7
Copy link
Owner

NicolasLopes7 commented Mar 4, 2024

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!

@NicolasLopes7 NicolasLopes7 added the good first issue Good for newcomers label Mar 4, 2024
@meiazero
Copy link
Contributor

meiazero commented Mar 4, 2024

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

@jotace1
Copy link

jotace1 commented Mar 4, 2024

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

@NicolasLopes7
Copy link
Owner

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!

@jotace1
Copy link

jotace1 commented Mar 4, 2024

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

@NicolasLopes7
Copy link
Owner

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

@meiazero
Copy link
Contributor

meiazero commented Mar 4, 2024

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 😄

@jotace1
Copy link

jotace1 commented Mar 4, 2024

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

@NicolasLopes7
Copy link
Owner

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

tyvm! godspeed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants