Azure / static-web-apps

Azure Static Web Apps. For bugs and feature requests, please create an issue in this repo. For community discussions, latest updates, kindly refer to the Discussions Tab. To know what's new in Static Web Apps, visit https://aka.ms/swa/ThisMonth
https://aka.ms/swa
MIT License
323 stars 54 forks source link

Support publishing a zip using Az CLI #7

Open JoeWirtley opened 4 years ago

JoeWirtley commented 4 years ago

I would like a way to be able to publish a static web app from my file system, not using GitHub (or DevOps).

CreativeNotice commented 4 years ago

Agreed. If Azure CLI supports this platform, it could be used for local system and 3rd party pipelines (Bitbucket, etc).

anthonychu commented 3 years ago

We're looking at adding deploying a zip from via the Azure CLI. This will initially take a URL to a zip file. It means you'll have to zip up the contents and make it available on a publicly accessible location. This could be a SAS URI to a zip file in Azure Blob Storage. The file can be deleted after deployment.

zerodogg commented 3 years ago

Do you have any rough timeframe for when this might be available for testing?

RossMurr4y commented 3 years ago

We're looking at adding deploying a zip from via the Azure CLI. This will initially take a URL to a zip file. It means you'll have to zip up the contents and make it available on a publicly accessible location. This could be a SAS URI to a zip file in Azure Blob Storage. The file can be deleted after deployment.

Could you explain the reason for this approach over something like pointing at a local zip file? Or even the build output directory and perform the archiving for us as is the case with ZipDeploy?

anthonychu commented 3 years ago

That comment was based on how the deployment api works. We’re also looking at other options right now to see how to best support local deployment.

mviegas commented 3 years ago

Hi @anthonychu! Just checking in: would you have any updates regarding this topic?

danielmackay commented 3 years ago

@anthonychu - any update on this?

We have a need to deploy to SWA's from Bit Bucket. I don't mind how this is done (although Azure CLI probably makes sense), but right now we cannot deploy to this Azure resource. This is a real gap in functionality as we can deploy all our other Azure resources though the other Bit Bucket Pipes or Azure CLI.

Would be great to see this gap filled ASAP.

lucashfreitas commented 3 years ago

@anthonychu thanks for the awesome service in the first point! :)

We have also faced this issue and were forced to create a new pipeline in Azure dev ops and we had to give up our standard pipelines setup which usually is using bitbucket/gitlab.

I am completely new to Azure and have been deploying serverless services using AWS/Cloudformation/ServerlessFramework /CDK, soI am sorry me in advance if I am saying something wrong. I came across a project where I had to use Azure to deploy a static app + serverless API. I've been reading many tutorials, examples, docs, etc but I feel that it lacks a fully automated way/examples to setup CI/CD for static web apps.

Most of the examples are tightened to GitHub workflow but would be really nice to have more docs/examples and to use azure CLI/ARM templates to do that. I've found some documentation at:

https://docs.microsoft.com/en-us/azure/static-web-apps/publish-azure-resource-manager?tabs=azure-cli#feedback https://docs.microsoft.com/en-us/azure/templates/microsoft.web/staticsites?tabs=json#Capability

But it is still not 100% clear on what is the best approach to follow here - also most of the example/blog posts use VS CODE Extension and Azure portal. It seems that the way to go is to use ARM templates - which also lack demos/examples.

This tutorial is amazing: https://docs.microsoft.com/en-us/azure/static-web-apps/local-development, but is still not 100% on how to do 100% automatic.

Thanks again :)

Ramblurr commented 3 years ago

@lucashfreitas Have you found a workflow for deploying azure static apps using the command line that could be built into a non-github workflow?

lucashfreitas commented 3 years ago

@Ramblurr not yet. Unfortunately, I ended up migrating the repo to Github :(. Also, we had a hard time setting up a 100% continuous integration flow using 100% automated scripts using ARM/Azure CLI. I did not find many examples only and have to dig deep into the docs but I managed to make it 85% automatic. The hard part is that we are deploying multiple applications using the same setup, so ideally we wanted just to plug our subscription ID + APP/Tenant Id.

There is a way to create the static app through the CLI but not deploy it.

anthonychu commented 3 years ago

Our first step for supporting non-GitHub based deployments might be to document how to run the Docker container that the GitHub action runs so that you can run it on your own environment. Obviously this requires Docker and might not be ideal for some scenarios. But this might be a short/medium term solution while we work on other solutions.

kepalas commented 3 years ago

In one of our projects, we use something like this to deploy to Azure Static WebApps from BitBucket pipelines:

    - step:
        name: Deploy web app
        image: mcr.microsoft.com/appsvc/staticappsclient:stable
        deployment: <environment>
        script:
          - /bin/staticsites/StaticSitesClient upload --verbose --app ./build --skipAppBuild true --apiToken $AZURE_STATICSITE_TOKEN

where the ./build folder contains the React based static app artifacts built in previous steps

matkoch commented 2 years ago

@kepalas I'm trying to port this into a console application. What's the deployment key here? Currently, I get the output deployment_action was not provided.

kepalas commented 2 years ago

As I mentioned before, that snippet is part of our BitBucket pipeline. The deployment key indicates which environment variables should be added to the runtime (more info can be found here).

You can find more info on how to use the StaticSitesClient binary by checking its help section: image

matkoch commented 2 years ago

Oh, I just quoted my arguments incorrectly... All good, thanks! :)

matkoch commented 2 years ago

@anthonychu i assume the code for staticsitesclient is not public, so debugging this is a bit cumbersome. maybe you can give a hint what's wrong here?

image

Edit:

Found it, there's a bug in the conversion from UploadOptions to ActionOptions. It doesn't set the ApiLocation:

image
frasbach commented 2 years ago

@matkoch Can you explain how to fix this? Or are we just stuck? :/

jamesmaila commented 2 years ago

@JustClueless and for those running into the api bug @matkoch found in the latest "stable" image, you can pin this version which has api publish function working as expected...

mcr.microsoft.com/appsvc/staticappsclient@sha256:57b6be4b785eccc666462f284457b72b0c09f6f5e6d067b965750233a417fd0e

Any idea when CLI compatible deployment tool will be officially supported / available for SWA?

paule96 commented 2 years ago

For everyone that is still searching for a way to just upload something from the command line, I wrote for myself a little script for this:

https://github.com/codez-one/CZ.Azure.FileExchange/blob/main/build/deploy.ps1

You can look into the readme how this works. But here some warnings:

Still it would be nice to have a build-in feature.

paule96 commented 2 years ago

another usecase is btw. if your dotnet build requires more tools then just dotnet. I my case this is sass. You can define every program call in your csproj for example.

And this make it impossible to use the build container.

mattwilson1024 commented 2 years ago

Having the ability to push pre-built artifacts to Static Web Apps via Azure CLI (ideally from a local folder) would be hugely beneficial and is a big gap in the product at the moment for teams like mine. In our case we use Bitbucket and CircleCI with some fairly complex build pipelines - moving away from that setup would have massively increased the scope (and politics) of adopting Azure for the hosting.

My workaround for now is:

It's obviously not ideal because it means two git repos, two separate CI workflows etc, but it is working well and I think seems like a more robust workaround than having to use the tools in an undocumented way. I can at least be confident that pushing to git from a bash script won't stop working with no notice.

Swapping that process out for a single CLI call in the future would be great.

akshayhebbarg commented 2 years ago

Check if this helps. https://www.akshayhebbar.com/

Reshmi-Sriram commented 2 years ago

Hi all, We have now officially announced the GA of Static Web Apps CLIπŸŽ‰πŸŽ‰ This is a power-packed tool which now enables features such as login, deploy from local, automatic framework detection and much more - all from your local development system! Do have a look and let us know how you like it :) (P.S. It is Open Source, so feel free to contribute to the next set of features you'd like to see!) 🌟

drmcclelland commented 2 years ago

Hi all, We have now officially announced the GA of Static Web Apps CLIπŸŽ‰πŸŽ‰ This is a power-packed tool which now enables features such as login, deploy from local, automatic framework detection and much more - all from your local development system! Do have a look and let us know how you like it :) (P.S. It is Open Source, so feel free to contribute to the next set of features you'd like to see!) 🌟

@Reshmi-Sriram - does Microsoft support the usage of the Static Web Apps CLI inside a Github Action yet? We typically first "build", then package the build output into a "release" (ZIP file), and finally "deploy" the contents of the release. We haven't yet found a way to do this with the official GitHub Action for deploying to Azure Static Web Apps.

manekinekko commented 2 years ago

@drmcclelland any reason you need to manually zip and then deploy?

The new SWA CLI does that automatically for you now, all you need is to run the swa command inside your local SWA project and follow the wizard.

In case you need to deploy from the CI/CD

Get the deployment token of your SWA project

  1. from your local machine:swa deploy --print-token

From a CI/CD:

  1. create a SWA_CLI_DEPLOYMENT_TOKEN env var and store the token
  2. build your project (or use swa build)
  3. deploy to SWA:swa deploy [--options] (read docs)
drmcclelland commented 2 years ago

Thanks for your response @manekinekko - we trigger our build/deploy steps upon creation of a "release" in our GitHub repo. First, the final output of the "build" step is zipped up and uploaded as a release asset. Next, the "deploy" step downloads and unzips the release asset, then pushes it to be deployed to Azure.

What I'd like to confirm is if Microsoft officially supports the usage of the swa CLI inside of a GitHub action? I only saw examples of local usage in the docs, but not inside a CI/CD pipeline.

manekinekko commented 2 years ago

We do support deploying from a CI/CD, using deployment tokens.

ShonP commented 1 month ago

+1 to that, specifically through az cli or biceps/arm templates