Let's Take a look at how to deploy a Blazor Static Site to an AWS S3 Bucket.
Published on September 27, 2020 by Coding Flamingo
AWS AWS S3 CI/CD Deploy
5 min READ
In this post we will create an AWS S3 bucket (using the portal) and then we are going to deploy our static site to it using GitHub Actions.
you can find all the code in: https://github.com/coding-flamingo/BlazorStaticDeploy
This finishes the AWS setup.
First we are going to create the workflow file for the GitHub Action, we first start with setting up the name for the Action and the trigger for the action (change this to the name you want and the trigger you want, this sample uses the name DeployToAWSS3 and it gets triggered when we push to the ‘dev’ branch)Full file:
name: DeployToAWSS3
on:
push:
branches:
- dev
Then if you have to compile your site (in this example we use a Blazor Site that needs to be compiled) you add your compiling steps and publish the artifacts for the deploy action to download (if you don’t have to compile your site, you can skip this but note the deploy action grabs from artifacts so you would have to change that).
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set up .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.102'
- name: Build with dotnet
run: dotnet build --configuration Release
- name: dotnet publish
run: dotnet publish -c Release -o $/blazorapp
- name: Publish artifacts
uses: actions/upload-artifact@master
with:
name: blazorStaticSite
path: $/blazorapp
Now for the deploy side of the file we are going to download the artifacts and then using the jakejarvis/s3-sync-action action we will push it to the bucket we created.
deploy:
needs: build
name: Deploy
runs-on: ubuntu-latest
steps:
# Download artifacts
- name: Download artifacts
uses: actions/download-artifact@master
with:
name: blazorStaticSite
- name: Deploy to S3 🚀
uses: jakejarvis/s3-sync-action@master
with:
args: --acl public-read --follow-symlinks --delete
env:
AWS_S3_BUCKET: 'blazorstaticsite'
AWS_ACCESS_KEY_ID: $
AWS_SECRET_ACCESS_KEY: $
AWS_REGION: 'us-west-2' # optional: defaults to us-east-1
SOURCE_DIR: 'wwwroot' # optional: defaults to entire repository
Now lets go through the variables of this section.
--acl public-read
which makes each file public ` –follow-symlinks which changes symbolic links to the files since AWS has problems with it and
–delete` which deletes any extra file in the bucket.AWS_ACCESS_KEY_ID
Note: the name is the same as we specified in the GitHub Action.AWS_SECRET_ACCESS_KEY
Note: the name is the same as we specified in the GitHub Action.You are done :)
Comments
No comments found for this article.
Join the discussion for this article by commenting in this ticket. Comments appear on this page instantly.