Deploying to Cloudflare Pages using Github Actions
· One min read
Cloudflare provides a great CDN with no egress charges on bandwidth. The best way to use Cloudflare is through Cloudflare Pages.
Using Cloudflare Pages should be pretty straightforward for most frameworks that generate a SPA. However, see the example below for how to use Cloudflare Pages from asset pipelines for Ruby on Rails and Django.
Example: Publish Django Static Files with GitHub Actions
Here is an example of using GitHub Actions to publish Django static files:
- name: Build Static Files
run: |
docker run --env STATIC_ROOT='/static-compiled/' \
--env DATABASE_URL='sqlite:///db.sqlite' \
-v $PWD/static:/app/static \
-v $PWD/static-compiled:/static-compiled \
$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \
python manage.py collectstatic --noinput
- name: Publish Static Files
uses: cloudflare/wrangler-action@2.0.0
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
accountId: ${{ secrets.CF_ACCOUNT_ID }}
command: pages publish ./static-compiled --project-name=opszero-static --commit-dirty=true