Skip to content

Commit

Permalink
add Cloud Storage Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
kahlstrm committed Jan 16, 2024
1 parent 1b177d7 commit 201e7a4
Show file tree
Hide file tree
Showing 6 changed files with 236 additions and 1 deletion.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ npm-debug.log
*.md
dist
uploads/
.env
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ PUBLIC_SERVER_URL="http://localhost:3001"
# variables required for Google OAuth 2.0, otherwise disabled
#CLIENT_ID=
#CLIENT_SECRET=

# Fill these in when deploying to staging/production, these tests values are here for local testing with docker-compose.azure.yml
# NOTE: these are not necessary for typical local development (seeding data is file-based), only for testing with the cloud storage
# AZURE_STORAGE_CONNECTION_STRING=DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://localhost:10000/devstoreaccount1;QueueEndpoint=http://localhost:10001/devstoreaccount1;
# AZURE_STORAGE_CONTAINER_NAME=az-media
# AZURE_STORAGE_ALLOW_CONTAINER_CREATE=true
# AZURE_STORAGE_ACCOUNT_BASEURL=http://localhost:10000/devstoreaccount1
2 changes: 2 additions & 0 deletions apps/cms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@azure/storage-blob": "^12.16.0",
"@payloadcms/bundler-webpack": "^1.0.6",
"@payloadcms/db-mongodb": "^1.3.1",
"@payloadcms/plugin-cloud-storage": "^1.1.1",
"@payloadcms/richtext-lexical": "^0.5.2",
"dotenv": "^16.3.1",
"express": "^4.18.2",
Expand Down
26 changes: 26 additions & 0 deletions apps/cms/src/payload.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { lexicalEditor } from "@payloadcms/richtext-lexical";
import type { Config } from "@tietokilta/cms-types/payload";
import { oAuthPlugin } from "payload-plugin-oauth";
import { buildConfig } from "payload/config";
import { cloudStorage } from "@payloadcms/plugin-cloud-storage";
import { azureBlobStorageAdapter } from "@payloadcms/plugin-cloud-storage/azure";
import { Media } from "./collections/media";
import { Pages } from "./collections/pages";
import { Topics } from "./collections/topics";
Expand All @@ -20,6 +22,16 @@ declare module "payload" {
// eslint-disable-next-line @typescript-eslint/no-empty-interface -- not applicable
export interface GeneratedTypes extends Config {}
}
const {
AZURE_STORAGE_CONNECTION_STRING,
AZURE_STORAGE_CONTAINER_NAME,
AZURE_STORAGE_ACCOUNT_BASEURL,
} = process.env;

const useCloudStorage =
typeof AZURE_STORAGE_CONNECTION_STRING === "string" &&
typeof AZURE_STORAGE_CONTAINER_NAME === "string" &&
typeof AZURE_STORAGE_ACCOUNT_BASEURL === "string";

export default buildConfig({
// TODO: should probably enable this for production but it breaks auth in development
Expand Down Expand Up @@ -109,5 +121,19 @@ export default buildConfig({
secret: process.env.PAYLOAD_SECRET ?? "",
},
}),
cloudStorage({
enabled: useCloudStorage,
collections: {
[Media.slug]: {
adapter: azureBlobStorageAdapter({
connectionString: AZURE_STORAGE_CONNECTION_STRING ?? "",
containerName: AZURE_STORAGE_CONTAINER_NAME ?? "",
allowContainerCreate:
process.env.AZURE_STORAGE_ALLOW_CONTAINER_CREATE === "true",
baseURL: AZURE_STORAGE_ACCOUNT_BASEURL ?? "",
}),
},
},
}),
],
});
16 changes: 16 additions & 0 deletions docker-compose.azure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: "3"
# NOTE: This is only for testing azure cloud storage, use local files for development
services:
azure-storage:
image: mcr.microsoft.com/azure-storage/azurite:latest
restart: always
command: "azurite --loose --blobHost 0.0.0.0 --tableHost 0.0.0.0 --queueHost 0.0.0.0 --skipApiVersionCheck"
ports:
- "10000:10000"
- "10001:10001"
- "10002:10002"
volumes:
- azurite:/opt/azurite

volumes:
azurite:
185 changes: 184 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 201e7a4

Please sign in to comment.