This guide will help you deploy the Inswags Django application to DigitalOcean App Platform.
- A DigitalOcean account
- A GitHub account
- Git installed on your local machine
-
Fork or push this repository to your GitHub account
Update the
.do/app.yamlfile with your GitHub username:github: branch: main deploy_on_push: true repo: your-github-username/Inswags
-
Create a new App on DigitalOcean App Platform
- Go to the DigitalOcean Cloud Control Panel
- Click on "Apps" in the left sidebar
- Click "Create App"
- Select "GitHub" as the source
- Connect your GitHub account if not already connected
- Select your repository (Inswags)
- Select the branch you want to deploy (main)
- Click "Next"
-
Configure your App
- The App Platform will detect that this is a Python application
- It will automatically use the settings from your
.do/app.yamlfile - Review the settings and make any necessary adjustments
- Click "Next"
-
Add a Database
- In the "Resources" section, click "Add Resource"
- Select "Database"
- Choose "Dev Database" for development or "Production Database" for production
- Click "Create and Attach"
-
Set Environment Variables
The following environment variables are already configured in the app.yaml file:
DEBUG: Set to "False" for productionSECRET_KEY: Will be automatically set from DigitalOcean's environmentDATABASE_URL: Will be automatically set to connect to your databaseALLOWED_HOSTS: Will be automatically set to your app's domain
For Digital Ocean Spaces integration, you'll need to add these additional environment variables:
USE_SPACES: Set to "True" to enable Digital Ocean Spaces for file storageSPACES_ACCESS_KEY_ID: Your Digital Ocean Spaces access keySPACES_SECRET_ACCESS_KEY: Your Digital Ocean Spaces secret keySPACES_BUCKET_NAME: The name of your Digital Ocean Spaces bucketSPACES_REGION: The region of your Digital Ocean Spaces (default is "nyc3")
-
Deploy your App
- Review all settings
- Click "Create Resources"
- Wait for the deployment to complete
-
Access your App
Once the deployment is complete, you can access your app at the URL provided by DigitalOcean.
To run this application locally:
-
Install dependencies:
pip install -r requirements.txt -
Run migrations:
python manage.py migrate -
Create a superuser:
python manage.py createsuperuser -
Run the development server:
python manage.py runserver
Ausgeswagt/: Main Django project directoryswags/: Django app directorytemplates/: HTML templatesstatic/: Static files (CSS, JavaScript, images)media/: User-uploaded files.do/: DigitalOcean App Platform configurationProcfile: Defines the command to run on the serverruntime.txt: Specifies the Python versionrequirements.txt: Lists all Python dependencies
This application can use Digital Ocean Spaces for storing user-uploaded files. Follow these steps to set it up:
-
Create a Spaces Bucket
- Go to the DigitalOcean Cloud Control Panel
- Click on "Spaces" in the left sidebar
- Click "Create a Space"
- Select a region (e.g., nyc3)
- Choose a unique name for your bucket
- Configure file access (recommended: "Restrict File Listing")
- Click "Create a Space"
-
Create Access Keys
- In the DigitalOcean Cloud Control Panel, go to "API" in the left sidebar
- Under "Spaces access keys", click "Generate New Key"
- Enter a name for your key
- Copy both the access key and secret key (you won't be able to see the secret key again)
-
Configure Environment Variables
- In your App Platform settings, add the environment variables listed in the "Set Environment Variables" section above
- Set
USE_SPACESto "True" - Add your access key, secret key, bucket name, and region
-
CORS Configuration (if needed)
- If you're uploading files directly from the browser, you may need to configure CORS
- In your Space settings, go to the "Settings" tab
- Under "CORS", add your app's domain to the "Origin" field
- Set "Allowed Methods" to include at least GET, PUT, POST
- Click "Save"