Web-based media browser written in Go.
Media Browser is a directory browser for Google Cloud Storage. Similar to common web servers' directory and file browsing capabilities, it allows user to browse a storage bucket via a simple web interface using hyperlinks.
Once a user selects an individual file, the server redirects the user to the Signed URL for the object in Cloud Storage. Since the intention of this app is browsing media, this feature reduces the runtime of the server itself and allow video media to be streamed directly from the storage bucket. This kind of optimization makes Media Browser a perfect fit for serverless platforms like Cloud Run.
The interface and HTTP responses are modeled after the Apache HTTPD directory browsing feature. This enables better compatibility with clients that are looking for that particular layout (ex. Kodi).
- Run
go build .
from the project directory to download packages and build the application. - Optional: Execute the steps in Google Cloud Setup to configure your own Google Cloud project.
- Set environment variables for your own Google Cloud project. See below
- Spin up the application by executing the
mediabrowser
executable with your environment variables configured.
GOOGLE_APPLICATION_CREDENTIALS
(required) - path to Google Cloud service account key file (JSON file); the service account must have Cloud Storage object reader and Secret Manager Secret Accessor roles- For local development, you may use your own account credentials by authenticating with the
gcloud
CLI.
- For local development, you may use your own account credentials by authenticating with the
BUCKET_NAME
(required) - name of the Google Cloud Storage bucket to browseSERVICE_ACCOUNT_NAME
(required) - name of the IAM service account used to access Cloud Storage and Secret ManagerPK_SECRET_NAME
(required) - resource ID of the secret storing the service account's private keyPORT
(optional) - set the port to expose the HTTP server onWEB_USERNAME
(optional) - username to expect for HTTP Basic AuthenticationWEB_PASSWORD
(optional) - password to expect for HTTP Basic Authentication
- Create a project for your app.
- Install the Google Cloud SDK locally as well as the
jq
program. Then, you may execute the deployment scriptdeploy-mediabrowser-dependencies.sh
with the name of your project as the first argument. This script performs the following operations:- Enables the Cloud APIs necessary for the app.
- Create a Cloud Storage bucket to serve media. No special permissions are required for the bucket.
- Create a service account to use for the app. Securely store the credentials file. Extract the private key. The service account needs permissions for:
- Reading Cloud Storage objects
- Reading Secret Manager payloads
- Store the private key as a secret in Secret Manager.
- Make sure that Cloud Build and Cloud Run are enabled (they are enabled by the deployment script), then execute a deployment of the app substituting the environment variables as needed:
Alternatively, you can set up a Cloud Build pipeline using the
gcloud run deploy mediabrowser --platform managed --region $REGION --image gcr.io/$PROJECT_ID/mediabrowser:latest --allow-unauthenticated --service-account $_SERVICE_ACCOUNT_EMAIL --set-env-vars BUCKET_NAME=$BUCKET_NAME,WEB_USERNAME=$WEB_USERNAME,WEB_PASSWORD=$WEB_PASSWORD,PK_SECRET_NAME=$PK_SECRET_NAME
cloudbuild.yaml
file included in the repo and trigger the pipeline. Note: within the Cloud Run environment, theGOOGLE_APPLICATION_CREDENTIALS
variable does not need to be specified - the specified service account is exposed to the runtime automatically. - Now, you should be able to upload media into your Cloud Storage bucket and navigate to the Cloud Run app URL to browse content.
Favicon Video File by Vicons Design from the Noun Project