S3 Bucket
Config
- stack.cue
- builder.cue
package main
import (
"stakpak.dev/devx/v1"
"stakpak.dev/devx/v1/traits"
)
stack: v1.#Stack
stack: {
$metadata: stack: "myapp"
components: {
bucket: {
traits.#S3CompatibleBucket
s3: {
prefix: "guku-io-"
name: "my-bucket-123"
versioning: true
objectLocking: false
}
}
}
}
package main
import (
"stakpak.dev/devx/v2alpha1"
"stakpak.dev/devx/v2alpha1/environments"
"stakpak.dev/devx/v1/components"
"stakpak.dev/devx/v1/transformers/compose"
tfaws "stakpak.dev/devx/v1/transformers/terraform/aws"
)
builders: v2alpha1.#Environments & {
dev: environments.#Compose & {
flows: "compose/add-compose-bucket": pipeline: [compose.#AddS3Bucket]
"components": {
myminio: {
components.#Minio
minio: {
urlScheme: "http"
userKeys: default: {
accessKey: "admin"
accessSecret: "adminadmin"
}
url: _
}
}
bucket: s3: {
url: myminio.minio.url
accessKey: myminio.minio.userKeys.default.accessKey
accessSecret: myminio.minio.userKeys.default.accessSecret
}
}
}
prod: flows: "terraform/add-bucket": pipeline: [tfaws.#AddS3Bucket]
}
Build
devx build dev
devx build prod
Result
- Dev
- Prod Terraform
docker-compose.yml
version: "3"
volumes:
miniodata: null
services:
myminio:
image: minio/minio:RELEASE.2023-01-02T09-40-09Z.fips
environment:
MINIO_ACCESS_KEY: admin
MINIO_SECRET_KEY: adminadmin
depends_on: []
ports:
- "9000:9000"
- "9001:9001"
command:
- server
- /data
- -console-address
- :9001
restart: always
volumes:
- miniodata:/data
bucket:
image: minio/mc
depends_on:
- myminio
entrypoint: |-
/bin/sh -c "
/usr/bin/mc alias set myminio http://myminio:9000 admin adminadmin;
/usr/bin/mc mb myminio/guku-io-my-bucket-123;
/usr/bin/mc policy set public myminio/guku-io-my-bucket-123;
exit 0;
"
restart: "no"
/build/prod/terraform/generated.tf.json
{
"resource": {
"aws_s3_bucket": {
"bucket": {
"bucket": "guku-io-my-bucket-123"
}
},
"aws_s3_bucket_versioning": {
"bucket": {
"bucket": "${aws_s3_bucket.bucket.bucket}",
"versioning_configuration": {
"status": "Enabled"
}
}
}
}
}