> ## Documentation Index
> Fetch the complete documentation index at: https://ayakaleaf-pro.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# S3

> Mantenha os arquivos e o histórico dos projetos em um armazenamento compatível com S3 em uma implantação no Kubernetes.

Os arquivos dos projetos e seu histórico são armazenados pelo serviço **history-v1**, e os arquivos de templates pelo serviço **filestore**, ambos dentro de cada pod do Ayakaleaf Pro. Por padrão, eles gravam no volume de dados; com o S3, gravam em buckets. Quais buckets e permissões são necessários está descrito em [S3](https://ayakaleaf-pro.mintlify.site/pt/on-premises/configuration/overleaf-toolkit/s3.md).

| | |
| - | - |
| Serviços | history-v1 (arquivos e histórico dos projetos), filestore (arquivos de templates), em cada pod do Ayakaleaf Pro |
| Pod → S3 | o endpoint do S3, para cada arquivo lido ou gravado |
| Obrigatório | para [várias réplicas](https://ayakaleaf-pro.mintlify.site/pt/on-premises/configuration/kubernetes/horizontal-scaling.md): seus volumes de dados não são compartilhados, os buckets sim |
| Tarefas periódicas | nenhuma |

> [!WARNING]
>
> Escolha o S3 antes que os usuários criem projetos. Uma instância que já mantém arquivos em seu volume precisa primeiro da [migração para o S3](https://ayakaleaf-pro.mintlify.site/pt/on-premises/maintenance/s3-migration.md).

### Configuração

**1. Buckets e chaves**

Crie os três buckets `overleaf-template-files`, `overleaf-project-blobs` e `overleaf-chunks` e os dois usuários restritos com o seu serviço S3, conforme descrito em [Configuração do S3](https://ayakaleaf-pro.mintlify.site/pt/on-premises/configuration/overleaf-toolkit/s3.md#s3-setup), ou execute o Garage no cluster como mostrado abaixo. Coloque as quatro chaves em um Secret:

```bash wrap theme={null}
kubectl -n overleaf create secret generic overleaf-s3 \
  --from-literal=OVERLEAF_FILESTORE_S3_ACCESS_KEY_ID=<filestore key> \
  --from-literal=OVERLEAF_FILESTORE_S3_SECRET_ACCESS_KEY=<filestore secret> \
  --from-literal=OVERLEAF_HISTORY_S3_ACCESS_KEY_ID=<history key> \
  --from-literal=OVERLEAF_HISTORY_S3_SECRET_ACCESS_KEY=<history secret>
```

**2. ConfigMap**

```yaml title="30-config.yaml (additions)" wrap theme={null}
  OVERLEAF_FILESTORE_BACKEND: s3
  OVERLEAF_FILESTORE_TEMPLATE_FILES_BUCKET_NAME: overleaf-template-files
  OVERLEAF_FILESTORE_S3_REGION: eu-west-1
  OVERLEAF_HISTORY_BACKEND: s3
  OVERLEAF_HISTORY_PROJECT_BLOBS_BUCKET: overleaf-project-blobs
  OVERLEAF_HISTORY_CHUNKS_BUCKET: overleaf-chunks
  OVERLEAF_HISTORY_S3_REGION: eu-west-1
  # a self-hosted S3 service also needs its endpoint and path-style addressing
  # OVERLEAF_FILESTORE_S3_ENDPOINT: http://garage:3900
  # OVERLEAF_FILESTORE_S3_PATH_STYLE: "true"
  # OVERLEAF_HISTORY_S3_ENDPOINT: http://garage:3900
  # OVERLEAF_HISTORY_S3_PATH_STYLE: "true"
```

**3. Adicione o Secret ao pod e reinicie**

No Deployment (ou StatefulSet), adicione o Secret ao lado dos outros:

```yaml theme={null}
          envFrom:
            - configMapRef: {name: overleaf-env}
            - secretRef: {name: overleaf-secrets}
            - secretRef: {name: overleaf-s3}
```

```bash theme={null}
kubectl apply -f 30-config.yaml -f 40-overleaf.yaml
kubectl -n overleaf rollout restart deployment/overleaf     # or statefulset/overleaf
```

### Garage no cluster

Sem um serviço S3, o [Garage](https://garagehq.deuxfleurs.fr/) é um pequeno servidor S3 que é executado no cluster. A configuração de [Escalonamento horizontal](https://ayakaleaf-pro.mintlify.site/pt/on-premises/configuration/kubernetes/horizontal-scaling.md) foi testada com ele. Os comandos abaixo geram as chaves e criam o próprio Secret `overleaf-s3`, então use-os em vez do comando do Secret da etapa 1.

> [!NOTE]
>
> O MinIO, usado no exemplo do Overleaf, não publica mais imagens de contêiner: `minio/minio` desapareceu do Docker Hub e do quay.io.

```yaml title="50-garage.yaml" wrap theme={null}
apiVersion: v1
kind: ConfigMap
metadata:
  name: garage-config
  namespace: overleaf
data:
  garage.toml: |
    metadata_dir = "/var/lib/garage/meta"
    data_dir = "/var/lib/garage/data"
    db_engine = "lmdb"
    replication_factor = 1
    rpc_bind_addr = "[::]:3901"
    rpc_public_addr = "127.0.0.1:3901"
    # rpc_secret and admin_token come from GARAGE_RPC_SECRET / GARAGE_ADMIN_TOKEN
    [s3_api]
    s3_region = "garage"          # Overleaf's OVERLEAF_*_S3_REGION must match
    api_bind_addr = "[::]:3900"
    [admin]
    api_bind_addr = "[::]:3903"
---
apiVersion: v1
kind: Service
metadata:
  name: garage
  namespace: overleaf
spec:
  selector:
    app: garage
  ports:
    - name: s3
      port: 3900
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: garage
  namespace: overleaf
spec:
  serviceName: garage
  replicas: 1
  selector:
    matchLabels:
      app: garage
  template:
    metadata:
      labels:
        app: garage
    spec:
      containers:
        - name: garage
          image: dxflrs/garage:v2.5.0
          env:
            - name: GARAGE_RPC_SECRET
              valueFrom: {secretKeyRef: {name: garage-secrets, key: rpc_secret}}
            - name: GARAGE_ADMIN_TOKEN
              valueFrom: {secretKeyRef: {name: garage-secrets, key: admin_token}}
          ports:
            - containerPort: 3900
          readinessProbe:
            tcpSocket:
              port: 3900
          resources:
            requests: {cpu: 50m, memory: 64Mi}
            limits: {memory: 512Mi}
          volumeMounts:
            - {name: config, mountPath: /etc/garage.toml, subPath: garage.toml}
            - {name: data, mountPath: /var/lib/garage}
      volumes:
        - name: config
          configMap:
            name: garage-config
  volumeClaimTemplates:
    - metadata:
        name: data
      spec:
        accessModes: [ReadWriteOnce]
        resources:
          requests:
            storage: 10Gi
```

Gere os segredos, inicie o Garage e, em seguida, crie o layout, os buckets e as duas chaves restritas. Os IDs de chave do Garage são `GK` seguido de 24 caracteres hexadecimais, e os segredos têm 64 caracteres hexadecimais:

```bash wrap theme={null}
kubectl -n overleaf create secret generic garage-secrets \
  --from-literal=rpc_secret="$(openssl rand -hex 32)" \
  --from-literal=admin_token="$(openssl rand -base64 32)"
kubectl -n overleaf create secret generic overleaf-s3 \
  --from-literal=OVERLEAF_FILESTORE_S3_ACCESS_KEY_ID="GK$(openssl rand -hex 12)" \
  --from-literal=OVERLEAF_FILESTORE_S3_SECRET_ACCESS_KEY="$(openssl rand -hex 32)" \
  --from-literal=OVERLEAF_HISTORY_S3_ACCESS_KEY_ID="GK$(openssl rand -hex 12)" \
  --from-literal=OVERLEAF_HISTORY_S3_SECRET_ACCESS_KEY="$(openssl rand -hex 32)"
kubectl apply -f 50-garage.yaml
kubectl -n overleaf rollout status statefulset/garage

g() { kubectl -n overleaf exec garage-0 -- /garage "$@"; }
s() { kubectl -n overleaf get secret overleaf-s3 -o jsonpath="{.data.$1}" | base64 -d; }
g layout assign -z dc1 -c 8G "$(g status 2>/dev/null | awk '/^[0-9a-f]{16}/{print $1; exit}')"
g layout apply --version 1
for b in overleaf-template-files overleaf-project-blobs overleaf-chunks; do g bucket create "$b"; done
g key import --yes -n overleaf-filestore "$(s OVERLEAF_FILESTORE_S3_ACCESS_KEY_ID)" "$(s OVERLEAF_FILESTORE_S3_SECRET_ACCESS_KEY)"
g key import --yes -n overleaf-history "$(s OVERLEAF_HISTORY_S3_ACCESS_KEY_ID)" "$(s OVERLEAF_HISTORY_S3_SECRET_ACCESS_KEY)"
g bucket allow --read --write overleaf-template-files --key overleaf-filestore
g bucket allow --read overleaf-project-blobs --key overleaf-filestore
g bucket allow --read --write overleaf-project-blobs --key overleaf-history
g bucket allow --read --write overleaf-chunks --key overleaf-history
```

As permissões correspondem às políticas em [S3](https://ayakaleaf-pro.mintlify.site/pt/on-premises/configuration/overleaf-toolkit/s3.md#access-policies). O Garage verifica a região: aqui ela é `garage`, e `OVERLEAF_*_S3_REGION` precisa ser a mesma.

Com o Garage, defina o endpoint, `PATH_STYLE: "true"` e a região `garage` para ambos os serviços no ConfigMap, como em `60-config.yaml` de [Escalonamento horizontal](https://ayakaleaf-pro.mintlify.site/pt/on-premises/configuration/kubernetes/horizontal-scaling.md).

### Várias réplicas

Todas as réplicas precisam usar os mesmos buckets e chaves. Faça backup dos buckets com as ferramentas do seu provedor de S3; assim, os discos próprios das réplicas não guardam nenhum dado que precise de backup.

### Testado no Kubernetes

No Kubernetes 1.37 com três réplicas e o Garage como acima, todos os testes ponta a ponta destas páginas que criam projetos, enviam arquivos, usam o histórico ou publicam templates foram aprovados e, depois, os buckets `overleaf-project-blobs`, `overleaf-chunks` e `overleaf-template-files` continham os objetos, enquanto o `/var/lib/overleaf/data/history` próprio das réplicas permaneceu vazio.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.