Skip to content

Commit 166a548

Browse files
committed
feat: remove custom env var validation for s3 driver
1 parent 6aa22ab commit 166a548

File tree

4 files changed

+77
-47
lines changed

4 files changed

+77
-47
lines changed

docker-compose.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: '3.9'
2-
31
services:
42
postgres:
53
image: postgres:15
@@ -24,3 +22,25 @@ services:
2422
command: -c 'mkdir -p /data/test && /usr/bin/minio server /data'
2523
ports:
2624
- 9000:9000
25+
environment:
26+
MINIO_ROOT_USER: access_key
27+
MINIO_ROOT_PASSWORD: secret_key
28+
29+
cache-server:
30+
build:
31+
dockerfile: Dockerfile
32+
context: .
33+
ports:
34+
- '3000:3000'
35+
depends_on:
36+
- minio
37+
38+
environment:
39+
API_BASE_URL: http://localhost:3000
40+
41+
STORAGE_DRIVER: s3
42+
STORAGE_S3_BUCKET: test
43+
44+
AWS_ACCESS_KEY_ID: access_key
45+
AWS_SECRET_ACCESS_KEY: secret_key
46+
AWS_ENDPOINT_URL: http://minio:9000

docs/content/2.storage-drivers/s3.md

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@ services:
2424

2525
STORAGE_DRIVER: s3
2626
STORAGE_S3_BUCKET: gh-actions-cache
27-
STORAGE_S3_ACCESS_KEY: access_key
28-
STORAGE_S3_SECRET_KEY: secret_key
2927

30-
STORAGE_S3_ENDPOINT: minio
31-
STORAGE_S3_PORT: '9000'
32-
STORAGE_S3_USE_SSL: 'false'
28+
AWS_ACCESS_KEY_ID: access_key
29+
AWS_SECRET_ACCESS_KEY: secret_key
30+
AWS_ENDPOINT_URL: http://minio:9000
3331
volumes:
3432
- cache-data:/app/.data
3533

@@ -47,6 +45,8 @@ volumes:
4745
4846
### `docker-compose` AWS S3 example
4947

48+
This example assumes that credentials are being provided by the environment, e.g. via an [instance profile](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_switch-role-ec2_instance-profiles.html) or [EKS IRSA](https://docs.aws.amazon.com/eks/latest/userguide/iam-roles-for-service-accounts.html).
49+
5050
```yaml [docker-compose.yml]
5151
version: '3.9'
5252
@@ -70,30 +70,65 @@ volumes:
7070

7171
### Environment Variables
7272

73-
Don't forget to set the `STORAGE_DRIVER` environment variable to `s3` to use the S3 storage driver.
73+
The only required S3-related environment variables are `STORAGE_DRIVER: s3` and `STORAGE_S3_BUCKET`. The rest of the environment variables are optional and depend on your S3-compatible storage provider.
74+
75+
The AWS SDK will automatically use any AWS credentials available in the environment, e.g. `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` and `AWS_REGION`. Outside of AWS, these environment variables can still be used to authenticate with S3-compatible storage, as seen in the Minio example above.
7476

75-
The AWS SDK will automatically use any AWS credentials available in the environment, e.g. `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` and `AWS_REGION`.
77+
Common environment variables are listed below. For a full list of configuration options, see the [AWS SDK documentation](https://docs.aws.amazon.com/sdkref/latest/guide/settings-reference.html#EVarSettings).
7678

7779
#### `STORAGE_S3_BUCKET`
7880

7981
Example: `gh-actions-cache`
8082

81-
The name of the S3 bucket used for storage.
83+
The name of the S3 bucket used for storage. This environment variable is always required.
84+
85+
#### `AWS_REGION`
86+
87+
Example: `us-east-1`
88+
89+
The AWS SDK relies on this variable being set. In the cache server, it defaults to `us-east-1` if not provided. This has no effect if you are using a non-AWS S3-compatible storage provider, such as MinIO.
90+
91+
#### `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`
92+
93+
Example:
94+
`AWS_ACCESS_KEY_ID: access_key`
95+
`AWS_SECRET_ACCESS_KEY: secret_key`
8296

83-
#### `STORAGE_S3_ENDPOINT`
97+
This is the access key/secret key used to authenticate with S3-compatible storage. If required to authenticate with your provider, these should be provided by the provider. Alternatively, you can use the `AWS_PROFILE` environment variable to specify a profile from your AWS credentials file.
8498

85-
Example: `s3.amazonaws.com`, `minio`
99+
#### `AWS_PROFILE`
86100

87-
The endpoint hostname for S3 storage.
101+
Example: `my-profile`
88102

89-
#### `STORAGE_S3_PORT`
103+
If you wish to run the cache server locally and utilize a profile from your AWS credentials file or local AWS CLI configuration, you can set the `AWS_PROFILE` environment variable to the name of the profile. Note that this will also require mounting the AWS credentials file into the container in order for the SDK to be able to find it.
90104

91-
Example: `443`, `9000`
105+
```yaml [docker-compose.yml]
106+
version: '3.9'
92107
93-
The port S3 storage is running on.
108+
services:
109+
cache-server:
110+
image: ghcr.io/falcondev-oss/github-actions-cache-server:latest
111+
ports:
112+
- '3000:3000'
113+
environment:
114+
API_BASE_URL: http://localhost:3000
115+
116+
STORAGE_DRIVER: s3
117+
STORAGE_S3_BUCKET: gh-actions-cache
118+
119+
AWS_PROFILE: my-profile
120+
121+
volumes:
122+
- cache-data:/app/.data
123+
# Mount the AWS CLI credentials and config into the container
124+
- ~/.aws:/root/.aws:ro
125+
126+
volumes:
127+
cache-data:
128+
```
94129

95-
#### `STORAGE_S3_USE_SSL`
130+
#### `AWS_ENDPOINT_URL`
96131

97-
Example: `false`
132+
Example: `http://minio:9000`
98133

99-
Whether to use SSL for S3 storage connections.
134+
This is the endpoint URL for the S3-compatible storage. This is only required if you are using a non-AWS S3-compatible storage provider, such as MinIO.

lib/storage/drivers/s3.ts

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,13 @@ import { streamToBuffer } from '~/lib/utils'
1717
export const s3Driver = defineStorageDriver({
1818
envSchema: z.object({
1919
STORAGE_S3_BUCKET: z.string().min(1),
20-
STORAGE_S3_ENDPOINT: z.string().optional(),
21-
STORAGE_S3_REGION: z.string().min(1).default('us-east-1'),
22-
STORAGE_S3_PORT: z.coerce.number().positive().optional(),
23-
STORAGE_S3_USE_SSL: z
24-
.string()
25-
.transform((v) => v === 'true')
26-
.optional(),
27-
STORAGE_S3_ACCESS_KEY: z.string().optional(),
28-
STORAGE_S3_SECRET_KEY: z.string().optional(),
29-
AWS_REGION: z.string().optional(),
30-
AWS_DEFAULT_REGION: z.string().optional(),
20+
// AWS SDK requires an AWS_REGION to be set, even if you're using a custom endpoint
21+
AWS_REGION: z.string().default('us-east-1'),
3122
}),
3223
async setup(options) {
33-
const protocol = options.STORAGE_S3_USE_SSL ? 'https' : 'http'
34-
const port = options.STORAGE_S3_PORT ? `:${options.STORAGE_S3_PORT}` : ''
35-
let credentials
36-
37-
if (options.STORAGE_S3_ACCESS_KEY && options.STORAGE_S3_SECRET_KEY) {
38-
credentials = {
39-
secretAccessKey: options.STORAGE_S3_SECRET_KEY,
40-
accessKeyId: options.STORAGE_S3_ACCESS_KEY,
41-
}
42-
}
43-
4424
const s3 = new S3Client({
45-
credentials,
46-
endpoint: options.STORAGE_S3_ENDPOINT
47-
? `${protocol}://${options.STORAGE_S3_ENDPOINT}${port}`
48-
: undefined,
49-
region: options.AWS_REGION ?? options.AWS_DEFAULT_REGION ?? options.STORAGE_S3_REGION,
5025
forcePathStyle: true,
26+
region: options.AWS_REGION,
5127
})
5228

5329
try {

nitro.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,4 @@ export default defineNitroConfig({
3838
exclude: ['../../docs'],
3939
},
4040
},
41-
compatibilityDate: '2025-02-01',
4241
})

0 commit comments

Comments
 (0)