By koteisaev
Hello!
I am new to DigitalOcean, and yet I was able to finally got working my experimental app just in few hours (mostly due to unexpected limitation of dev databases to only Postgres while I was planning to use MongoDb, otherwise it would be even faster).
This is anyway much f***ng faster than inability getting verification call from AWS at all after waiting for 2 days.
My app is yet too small to scale out with Spaces, but I want to experiment a bit with following: my static assets webpack-ed during npm build as part of image creation, and what I would like to do is to upload the webpack-ed content to a space 'project-name-staticat path like/static/{config-name}/{git-tag}`, with autogeneration of env image variable like
STATIC_CONTENT_PATH="/static/${configuration_name}/${app_git_tag-or-other-deployment-id-value}"
where ${configuration_name} is my CONFIGURATION_NAME variable I set at app component where repo content is deployed to.
Binding prefix like /static/* to a Space looks to be the easiest part of all this, I guess?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hey!
Here’s a guide on how to achieve reliable deployment of your webpack-ed static content to a DigitalOcean Space during the container image build process:
1. Dockerfile Setup:
Here’s an example Dockerfile:
# Stage 1: Build stage
FROM node:lts-alpine as build-stage
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY ./ ./
RUN npm run build
# Stage 2: Production stage
FROM nginx:alpine
COPY --from=build-stage /app/build /usr/share/nginx/html # Copy build output
# -- Optional: Configure Nginx as needed --
2. Workflow Automation (CI/CD)
Here’s a basic example using GitHub Actions:
name: Build and Deploy to App Platform and Spaces
on:
push:
branches: [ main ]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build Docker Image
run: docker build -t my-image:latest .
- name: Login to DigitalOcean Container Registry
uses: docker/login-action@v2
with:
registry: registry.digitalocean.com
username: ${{ secrets.DO_ACCESS_TOKEN }}
password: ${{ secrets.DO_ACCESS_TOKEN }}
- name: Push to Container Registry
run: docker push my-image:latest
- name: Deploy to App Platform
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DO_ACCESS_TOKEN }}
app: ${{ secrets.DO_APP_ID }} # Replace with your App ID
spec: ${{ path/to/your/app.yaml }}
- name: Upload to Spaces
uses: digitalocean/spaces-upload-action@v1
with:
spaces_access_id: ${{ secrets.DO_SPACES_ACCESS_ID }}
spaces_secret_key: ${{ secrets.DO_SPACES_SECRET_KEY }}
space: ${{ secrets.DO_SPACES_NAME }}
region: ${{ secrets.DO_SPACES_REGION }}
source_dir: build/ # Output from Webpack
dest_dir: /static/${{ github.event.repository.name }}/${{ github.sha }}
Explanation:
dest_dir ensures assets from each build are in unique folders, helping with versioning if needed.Best,
Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.