Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploying from Azure DevOps Pipeline Releases #368

Closed
tylerewillis opened this issue Apr 15, 2021 · 7 comments
Closed

Deploying from Azure DevOps Pipeline Releases #368

tylerewillis opened this issue Apr 15, 2021 · 7 comments

Comments

@tylerewillis
Copy link

Similar to this which works great for deploying from DevOps pipelines, can we get support for deploying directly from pipeline releases in ADO? Thanks.

@craig-oncode
Copy link

I tried publishing my source code to a artifact location as shown below...

# JOB: Gather Static Web App Source Code
  - job: GatherStaticWebApp
    displayName: 'Gather Static Web App Source Code'
    steps:

    # TASK: Publish Static Web App Artifacts
    - task: PublishBuildArtifacts@1
      displayName: 'Publish Artifact: staticwebapp_drop'
      inputs:
        PathtoPublish: 'src'  # Folder location of source code in git repo
        ArtifactName: 'staticwebapp_drop'

I then tried to set the inputs the downloaded source code location, but no luck so far. Any help would be greatly appricated.

  # DEPLOYMENT: Deploy Static Web App
  - deployment: DeployStaticWebApp
    displayName: 'Deploy Static Web App'
    pool:
      vmImage: ubuntu-latest
    environment: DEV
    strategy:
      runOnce:
        deploy:
          steps:
    
          # TASK: Deploy My App
          - task: AzureStaticWebApp@0
            displayName: 'Deploy My App'
            inputs:
              app_location: '$(Pipeline.Workspace)/staticwebapp_drop/MyApp.Web'
              output_location: 'wwwroot'
              api_location: '$(Pipeline.Workspace)/staticwebapp_drop/MyApp.Api'
              routes_location: '$(Pipeline.Workspace)/staticwebapp_drop/MyApp.Web/wwwroot'
            env:
              azure_static_web_apps_api_token: $(deployment_token_dev)

Below is the error I keep getting...

App Directory Location: '/home/vsts/work/1/staticwebapp_drop/MyApp.Web' is invalid. Could not detect this directory. Please verify your workflow reflects your repository structure.

Craig

@craig-oncode
Copy link

craig-oncode commented Apr 16, 2021

Based on the error in my previous post, it will only scan your repo for the files to build and pull into the Static Web App. I could just use another job to deploy the web app, instead of a deployment, but this defeats my purpose of putting approval gates in for each of my environments.

If I find a way to get this to work, I will try to reply back to this thread.

@lukju
Copy link

lukju commented Apr 20, 2021

@craigholdheide i'm trying to do exactly the same. have you maybe found a solution for this?

@craig-oncode
Copy link

@lukju I ended up creating a PROD stage with a job to run the static web app deploy task. I also created an approve stage that does nothing more than echo the text "Approved to PROD". Since this is a deployment, I can add an environment to it, called ApproveToProd, and then created a preapproval.

Below are the last two stages of my yml deployment script if that helps.

Also, I found this documentation below to be helpful...

# DEV Stage before the approve stage not shown
#   DEV stage similar to PROD stage

# STAGE: APPROVE  
- stage: APPROVE
  jobs:

  # DEPLOYMENT: ApproveToProd
  - deployment: ApproveToProd
    displayName: Approve To PROD
    pool:
      vmImage: ubuntu-latest
    environment: ApproveToProd
    strategy:
      runOnce:
        deploy:
          steps:
          - script: echo Approved to PROD


# STAGE: PROD
- stage: PROD
  jobs:

  # JOB: Deploy Static Web App
  - job: DeployStaticWebApp
    displayName: 'Deploy Static Web App'
    pool:
      vmImage: ubuntu-latest
    steps:
    
      # TASK: Deploy Blazor App
      - task: AzureStaticWebApp@0
        displayName: 'Deploy Blazor App'
        inputs:
          app_location: 'src/MyApp.Web'
          output_location: 'wwwroot'
          api_location: 'src/MyApp.Api'
          routes_location: 'src/MyApp.Web/wwwroot'
        env:
          azure_static_web_apps_api_token: $(deployment_token_prod)

Unfortunately this is not the solution I hoped for, but the Azure Static Web App deploy task seems to only want to pull from source control and not from and artifact location. Hopefully this helps.

@zamzowd
Copy link

zamzowd commented Apr 23, 2021

It looks like AzureStaticWebApp is set up as a combined build and deploy in a single task?

I would prefer if these were separate tasks (or more likely, just a AzureStaticWebApp Deploy task, with the expectation that any static app framework will have its own independent Build tasks), with similar goal as others in this thread: have a Build stage that creates an artifact, followed by Deploy stages using that artifact.

It looks like there's been some updates to this task in a 0.0.1-preview branch that has not been published for use, including a skip_app_build input.

It seems to use a Docker image mcr.microsoft.com/appsvc/staticappsclient:stable, but I couldn't find source code for that. I suppose running in a Docker container is why it can't look at the agent's workspace directory?

@blockrobbe
Copy link

I had the same issue, took me a while but I worked out a different workaround that lets you keep using a deployment job, with the difference that you do check out the full repository (which is not the default behaviour for deployment jobs). I figured: it works if I build from my source code, so what if I download the prebuilt artifact into the directory in which the build output is normally written? If pointing the app_location directly to this location instead of the root, Oryx fails to detect what type of project it is, skips the build step and assumes the assets are already built in the directory. (Seems that it even ignores the build directory in that case? I did not check it since it already worked by then and I just went with it...)
The relevant pieces of our pipeline:

Build stage - I skipped the build steps as these are highly dependent from your project, the artifacts publishing is the relevant part:

stages:
  - stage: Build
    jobs:
      - job: Build
        displayName: "Build & publish"
        steps:
          ### Build steps - redacted away ###
          - publish: ./src/website/build  # Notice the directory being published
            artifact: website
            displayName: "Publish website artifacts"

Deploy stage (which is in a different template which has environment as an input parameter):

stages:
  - stage: "${{ parameters.environment }}"
    displayName: "Deploy to ${{ parameters.environment }}"
    jobs:
      - deployment: DeployTo${{ parameters.environment }}
        displayName: "Deploy to ${{ parameters.environment }}"
        environment: "kmodo-${{ parameters.environment }}"
        strategy:
          runOnce:
            deploy:
              steps:
                # Check out the source code manually as this is not done automatically and
                # it seems AzureStaticWebApp@0 needs this in order to function properly
                - checkout: self
                  submodules: true
                # Download artifacts manually so we can tweak the target directory.
                # Needed so we can point AzureStaticWebApp@0 to the pre-built assets.
                - task: DownloadPipelineArtifact@2
                  inputs:
                    artifact: website
                    path: ./src/website/build # Put the assets back where they came from!
                    displayName: "Download website artifacts"
                - task: AzureStaticWebApp@0
                  inputs:
                    # Point to the pre-built assets so Oryx build fails and it assumes it was already built
                    app_location: "src/website/build"
                  env:
                    azure_static_web_apps_api_token: $(kmodo-${{ parameters.environment }}-swa-deployment-token)

And the relevant pieces of the pipeline output:

2021-05-19T21:20:42.6115612Z ##[section]Starting: DownloadPipelineArtifact
2021-05-19T21:20:42.6136833Z ==============================================================================
2021-05-19T21:20:42.6137410Z Task         : Download Pipeline Artifacts
2021-05-19T21:20:42.6137780Z Description  : Download build and pipeline artifacts
2021-05-19T21:20:42.6138147Z Version      : 2.178.0
2021-05-19T21:20:42.6138581Z Author       : Microsoft Corporation
2021-05-19T21:20:42.6139063Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/download-pipeline-artifact
2021-05-19T21:20:42.6139709Z ==============================================================================
2021-05-19T21:20:43.0513358Z Download from the specified build: #253
2021-05-19T21:20:43.0534535Z Download artifact to: /home/vsts/work/1/s/src/website/build
...
2021-05-19T21:20:45.1911436Z Download completed.
...
2021-05-19T21:20:45.8923023Z Downloading artifact finished.
2021-05-19T21:20:45.8996615Z ##[section]Finishing: DownloadPipelineArtifact

and finally the deploy:

Starting: AzureStaticWebApp
==============================================================================
Task         : Deploy Azure Static Web App
Description  : [PREVIEW] Build and deploy an Azure Static Web App
Version      : 0.1.0
Author       : Microsoft Corporation
Help         : https://aka.ms/swadocs
==============================================================================
/usr/bin/bash /home/vsts/work/_tasks/AzureStaticWebApp_18aad896-e191-4720-88d6-8ced4806941a/0.1.0/launch-
docker.sh
########################################
# docker image pulling - redacted away #
########################################
App Directory Location: 'src/website/build' was found.
No Api directory specified. Azure Functions will not be created.
Starting to build app with Oryx
Azure Static Web Apps utilizes Oryx to build both static applications and Azure Functions. You can find more details on Oryx here: https://github.com/microsoft/Oryx
---Oryx build logs---


Operation performed by Microsoft Oryx, https://github.com/Microsoft/Oryx
You can report issues at https://github.com/Microsoft/Oryx/issues

Oryx Version: 0.2.20210410.1, Commit: e73613ae1fd73c809c00f357f8df91eb984e1158, ReleaseTagName: 20210410.1

Build Operation ID: |HFXsxySYd9M=.cf65ad76_
Repository Commit : 61ef03fe6d93a426671fb55051cb28bc51b166e6

Detecting platforms...
Could not detect any platform in the source directory.
Error: Could not detect the language from repo.


---End of Oryx build logs---
Oryx was unable to determine the build steps. Continuing assuming the assets in this folder are already built. If this is an unexpected behavior please contact support.
Finished building app with Oryx
Zipping App Artifacts
Done Zipping App Artifacts
Either no Api directory was specified, or the specified directory was not found. Azure Functions will not be created.
Uploading build artifacts.
Finished Upload. Polling on deployment.
Status: InProgress. Time: 0.2483925(s)
Status: InProgress. Time: 16.5265485(s)
Status: Succeeded. Time: 31.6661931(s)
Deployment Complete :)
Visit your site at: XXXXXXX
::set-output name=static_web_app_url::XXXXXXXX
Thanks for using Azure Static Web Apps!
Exiting

Finishing: AzureStaticWebApp

As you can see in the above logs, Oryx is unable to determine the language (and thus the build steps) and assumes the assets are already built. It then continues the deployment, which succeeds.
Side note: I know from previous attempts that it checks that there is an index.html-like file in the app_location to check if the assets were indeed built correctly before continuing the deployment after the Oryx build. If it cannot find such a file (e.g. due to a wrong configuration or so), it aborts the deployment and marks the task as failed.
It would be nice to tell the task to skip the build step completely using the skip_app_build, for which can find traces in the code in the master branch by now, but unfortunately trying to pass it as an input or as part of the env into the task, does not differ in the behaviour of the task.

Hope this helps!

@Reshmi-Sriram
Copy link

skip_app_build and skip_api_build are now available as solutions to split the build and deploy.
Marking this issue as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants