diff --git a/docker-compose.yml b/docker-compose.yml index afc04c0..2d94d71 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: '3' +version: "3" x-s3-client-env: &s3-client-env AWS_REGION: ${AWS_REGION:-"us-east-1"} @@ -7,7 +7,6 @@ x-s3-client-env: &s3-client-env AWS_S3_ENDPOINT: ${AWS_S3_ENDPOINT:-"http://minio:9000"} AWS_S3_BUCKET: ${AWS_S3_BUCKET:-"placeos-drivers-build-service"} - services: test: build: @@ -24,14 +23,14 @@ services: - minio - testbucket environment: - << : *s3-client-env + <<: *s3-client-env # Environment GITHUB_ACTION: ${GITHUB_ACTION:-} SG_ENV: ${SG_ENV:-development} - SPEC_ARGUMENTS: '' + SPEC_ARGUMENTS: "" TIMEOUT: 200 - OTEL_CRYSTAL_DISABLE_INSTRUMENTATION_HTTP_CLIENT: 'false' - + OTEL_CRYSTAL_DISABLE_INSTRUMENTATION_HTTP_CLIENT: "false" + minio: image: minio/minio:latest volumes: @@ -40,7 +39,7 @@ services: - 9000:9000 - 9090:9090 environment: - << : *s3-client-env + <<: *s3-client-env MINIO_ACCESS_KEY: $AWS_KEY MINIO_SECRET_KEY: $AWS_SECRET command: server /data --console-address ":9090" @@ -50,15 +49,15 @@ services: depends_on: - minio environment: - << : *s3-client-env + <<: *s3-client-env entrypoint: > sh -c ' sleep 3 && - mc config host add s3 $AWS_S3_ENDPOINT $AWS_KEY $AWS_SECRET && + mc alias set s3 $AWS_S3_ENDPOINT $AWS_KEY $AWS_SECRET && mc mb -p s3/$AWS_S3_BUCKET && exit 0 ' volumes: s3: - driver: local \ No newline at end of file + driver: local diff --git a/spec/api_spec.cr b/spec/api_spec.cr index 4884299..a8af8b4 100644 --- a/spec/api_spec.cr +++ b/spec/api_spec.cr @@ -122,6 +122,7 @@ module PlaceOS::Api json.has_key?(k).should be_true end + json["url"].as_s.starts_with?(PlaceOS::Api::AWS_S3_ENDPOINT.not_nil!).should be_true # compiled driver should return metadata resp = client.get("#{namespace}/metadata/#{uri}?#{params}") resp.status_code.should eq 200 diff --git a/src/placeos-build-api/s3.cr b/src/placeos-build-api/s3.cr index fb3b8a4..7aed159 100644 --- a/src/placeos-build-api/s3.cr +++ b/src/placeos-build-api/s3.cr @@ -111,11 +111,14 @@ module PlaceOS::Api end def url : String - scheme = "https://" + scheme = "https" host = nil + force_path_style = false if h = hostname + force_path_style = true scheme, host = h end + options = Awscr::S3::Presigned::Url::Options.new( aws_access_key: AWS_KEY, aws_secret_key: AWS_SECRET, @@ -127,7 +130,9 @@ module PlaceOS::Api expires: AWS_S3_LINK_EXPIRY.to_i.to_i32, additional_options: { "Content-Type" => "binary/octet-stream", - }) + }, + force_path_style: force_path_style, + ) url = Awscr::S3::Presigned::Url.new(options) Log.debug { "Generating signed URL}" } url.for(:get) @@ -173,7 +178,7 @@ module PlaceOS::Api private def hostname if h = AWS_S3_ENDPOINT uri = URI.parse(h) - {"#{uri.scheme}://", "#{uri.hostname}:#{uri.port}"} + {"#{uri.scheme}", "#{uri.hostname}:#{uri.port}"} end end end diff --git a/test b/test index f1f792f..1536c38 100755 --- a/test +++ b/test @@ -6,7 +6,7 @@ set -e function trap_ctrlc () { echo "░░░ Cleaning up..." - docker-compose down + docker compose down exit 2 } @@ -14,14 +14,14 @@ function trap_ctrlc () # when signal 2 (SIGINT) is received trap "trap_ctrlc" 2 -docker-compose pull +docker compose pull -docker-compose build +docker compose build exit_code="0" -docker-compose run --rm test $@ || exit_code="$?" +docker compose run --rm test $@ || exit_code="$?" -docker-compose down +docker compose down exit ${exit_code}