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

feat: Create dockerfile to run the tests #69

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
19 changes: 17 additions & 2 deletions bin/configure_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ def configure_profiles(profiles):
if not (endpoint and access_key and secret_key and region):
print(f"Perfil {profile_name} está incompleto. Ignorando...")
continue

if (access_key == "YOUR-KEY-ID-HERE" or secret_key == "YOUR-SECRET-KEY-HERE" ):
print(f"Perfil {profile_name} está incompleto. Ignorando...")
continue

set_aws_profiles(profile_name=profile_name, data=profile_data)
set_rclone_profiles(profile_name=profile_name, data=profile_data)
Expand All @@ -91,7 +95,18 @@ def configure_profiles(profiles):
if __name__ == "__main__":
if len(sys.argv) > 1:
with open(sys.argv[1], 'r') as file:
profiles = yaml.safe_load(file)
profiles_list = yaml.safe_load(file)
profiles = {}
for profile in list(profiles_list.items())[2][1]:
if not isinstance(profile, dict):
profiles = profiles_list
break
profiles[profile.get("profile_name")] = {}
profiles[profile.get("profile_name")]["endpoint"] = profile.get("endpoint_url")
profiles[profile.get("profile_name")]["access_key"] = profile.get("aws_access_key_id")
profiles[profile.get("profile_name")]["secret_key"] = profile.get("aws_secret_access_key")
profiles[profile.get("profile_name")]["region"] = profile.get("region_name")

else:
profiles_data = os.getenv("PROFILES")
if not profiles_data:
Expand All @@ -101,4 +116,4 @@ def configure_profiles(profiles):

print(f"Number of profiles - {len(profiles)}")
configure_profiles(profiles)
print(f"Profile Configurations Done!")
print("Profile Configurations Done!")
46 changes: 46 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
FROM ubuntu:latest

ARG AWS_CLI_VERSION="2.15.27"
ARG RCLONE_VERSION="1.66.0"
ARG MGC_VERSION="0.34.1"

RUN apt-get update && \
apt-get install -y \
curl \
unzip \
python3 \
python3-pip \
git

RUN mkdir -p /tools && \
curl -Lo rclone.zip "https://downloads.rclone.org/v${RCLONE_VERSION}/rclone-v${RCLONE_VERSION}-linux-amd64.zip" && \
unzip -q rclone.zip && rm rclone.zip && \
mv rclone-v${RCLONE_VERSION}-linux-amd64 /tools/ && \
ln -s "/tools/rclone-v${RCLONE_VERSION}-linux-amd64/rclone" /usr/local/bin/rclone


RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \
unzip awscliv2.zip && \
./aws/install

ARG MGC_VERSION
RUN curl -Lo mgc.tar.gz "https://github.com/MagaluCloud/mgccli/releases/download/v${MGC_VERSION}/mgccli_${MGC_VERSION}_linux_amd64.tar.gz" && \
tar xzvf mgc.tar.gz && rm mgc.tar.gz && \
ln -s "/tools/mgc" /usr/local/bin/mgc


RUN curl -LsSf https://astral.sh/uv/install.sh | sh && \
ln -s $HOME/.local/bin/uv /usr/local/bin/uv

# Define o diretório de trabalho para a raiz do projeto
WORKDIR /app

# Copia todo o conteúdo da pasta raiz do repositório para dentro do contêiner
COPY ../ /app


# Tornar o script executável
RUN chmod +x ./docker/entrypoint.sh

# Definir o script como ponto de entrada
ENTRYPOINT ["./docker/entrypoint.sh"]
23 changes: 23 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Running S3 Specs with Docker

1. Edit params.example.yaml file adding at least 3 profiles with a valid credentials.

2. Pull the container
```bash
docker build -t s3specs -f docker/Dockerfile .
```

3. Run all tests
```bash
docker run --rm -it s3specs uv run pytest --config ./params.example.yaml ./docs/ --tb=line
```

4. Run tests by category
```bash
docker run --rm -it s3specs uv run pytest --config ./params.example.yaml ./docs/ -m "categoryname" --tb=line
```

5. Run tests excluding category
```bash
docker run --rm -it s3specs uv run pytest --config ./params.example.yaml ./docs/ -m "not categoryname" --tb=line
```
10 changes: 10 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -e

#configure profiles
uv run ./bin/configure_profiles.py params.example.yaml

uv sync

# Executar o comando passado para o contêiner
exec "$@"
14 changes: 14 additions & 0 deletions params.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,27 @@ profiles:
-
profile_name: "br-se1"
policy_wait_time: 120
aws_access_key_id: "YOUR-KEY-ID-HERE"
aws_secret_access_key: "YOUR-SECRET-KEY-HERE"
endpoint_url: "https://br-se1.magaluobjects.com/"
region_name: "br-se1"
-
profile_name: "br-se1-second"
policy_wait_time: 120
aws_access_key_id: "YOUR-KEY-ID-HERE"
aws_secret_access_key: "YOUR-SECRET-KEY-HERE"
endpoint_url: "https://br-se1.magaluobjects.com/"
region_name: "br-se1"
-
profile_name: "br-ne1"
aws_access_key_id: "YOUR-KEY-ID-HERE"
aws_secret_access_key: "YOUR-SECRET-KEY-HERE"
endpoint_url: "https://br-se1.magaluobjects.com/"
region_name: "br-se1"
-
profile_name: "br-ne1-second"
aws_access_key_id: "YOUR-KEY-ID-HERE"
aws_secret_access_key: "YOUR-SECRET-KEY-HERE"
-
region_name: "br-ne1"
endpoint_url: "https://br-se1.magaluobjects.com/"
Expand Down