Skip to content

Commit

Permalink
Migrate to GitHub Actions and Azure App Service (#312)
Browse files Browse the repository at this point in the history
* Update local build instructions and README
* rename main site configuration files to be main-site*.json
* provide a local Docker image to run DocFX as a convenience
* Bump DocFX versions to 2.59.2

Co-authored-by: Chris Cheetham <[email protected]>
Co-authored-by: bart-vmware <[email protected]>
  • Loading branch information
3 people authored Feb 7, 2024
1 parent 25e6b37 commit acc12e9
Show file tree
Hide file tree
Showing 31 changed files with 368 additions and 347 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/build-APIdocs-layer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: build-api-docs
on:
pull_request:
branches:
- main
paths:
- .github/workflows/build-APIdocs-layer.yml
- Dockerfile-metadata

push:
branches:
- main
paths:
- .github/workflows/build-APIdocs-layer.yml
- Dockerfile-metadata

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
tagv2: 2.5.5
tagv3: 3.2.6

permissions:
contents: 'read'

jobs:
build-push:
name: Build and push API docs layer
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set Steeltoe versions to use
run: |-
echo '2:'${{ env.tagv2 }} > metadata.conf
echo '3:'${{ env.tagv3 }} >> metadata.conf
echo "STEELTOE_VERSIONS=${{ env.tagv2 }}-${{ env.tagv3 }}" >> $GITHUB_ENV
shell: bash

- name: Login to container registry
uses: docker/login-action@v3
with:
registry: "${{ vars.DOCKER_REGISTRY }}"
username: "${{ secrets.DOCKER_USERNAME }}"
password: "${{ secrets.DOCKER_PASSWORD }}"

- name: Build image
run: docker build . --file "Dockerfile-metadata" -t ${{ vars.DOCKER_REGISTRY }}/documentation-metadata:${{ env.STEELTOE_VERSIONS }}

- name: Push image
if: ${{ github.event_name != 'pull_request' }}
run: docker push ${{ vars.DOCKER_REGISTRY }}/documentation-metadata:${{ env.STEELTOE_VERSIONS }}
91 changes: 91 additions & 0 deletions .github/workflows/build-and-stage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: build-website
on:
workflow_run:
workflows: [build-api-docs]
types: [completed]
pull_request:
branches:
- main
paths:
- "*"
- "!README.md"
- "!docfx/"
- "!build-metadata.sh"
- "!metadata.conf"
push:
branches:
- main
paths:
- "*"
- "!README.md"
- "!docfx/"
- "!build-metadata.sh"
- "!Dockerfile-metadata"
- "!metadata.conf"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: 'read'
pull-requests: 'write'

env:
IMAGE_TAG: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || github.run_id }}

jobs:
build-push-deploy:
name: Build and push documentation image
environment:
name: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || vars.STAGING_SLOT_NAME }}
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
env:
SLOT_NAME: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || vars.STAGING_SLOT_NAME }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Login to Azure
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

- name: Login to container registry
uses: azure/docker-login@v1
with:
login-server: "${{ vars.DOCKER_REGISTRY }}"
username: "${{ secrets.DOCKER_USERNAME }}"
password: "${{ secrets.DOCKER_PASSWORD }}"

- name: Build image
run: docker build . --file "Dockerfile" -t ${{ vars.DOCKER_REGISTRY }}/documentation:${{ env.IMAGE_TAG }}

- name: Push image
run: docker push ${{ vars.DOCKER_REGISTRY }}/documentation:${{ env.IMAGE_TAG }}

- name: If PR, create a new staging slot
if: ${{ github.event_name == 'pull_request' }}
run: az webapp deployment slot create --resource-group ${{ vars.AZURE_RESOURCE_GROUP }} --name ${{ vars.AZURE_WEBAPP_NAME}} --slot ${{ env.SLOT_NAME }}

- name: Deploy to staging slot
uses: azure/webapps-deploy@v3
id: deploy-to-webapp
with:
app-name: ${{ vars.AZURE_WEBAPP_NAME }}
images: ${{ vars.DOCKER_REGISTRY }}/documentation:${{ env.IMAGE_TAG }}
slot-name: ${{ env.SLOT_NAME }}

- name: If PR, comment with the preview link
if: ${{ github.event_name == 'pull_request' }}
uses: mshick/add-pr-comment@v2
with:
message: |
## Preview link: https://${{ vars.AZURE_WEBAPP_NAME }}-${{ env.SLOT_NAME }}.azurewebsites.net
- Your changes have been deployed to the preview site. The preview site will update as you add more commits to this branch.
- The preview link is shareable, but will be deleted when the pull request is merged or closed.
> *This is an automated message.*
repo-token: ${{ secrets.GITHUB_TOKEN }}

43 changes: 43 additions & 0 deletions .github/workflows/build-base-layer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: build-base-layer
on:
push:
branches:
- main
paths:
- .github/workflows/build-base-layer.yml
- docfx/

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
docfxVersion: 2.59.2

permissions:
contents: 'read'

jobs:
build-push:
name: Build and push base layer
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set DocFX version to use
run: echo v${{ env.docfxVersion }} > docfx/version
shell: bash

- name: Login to container registry
uses: docker/login-action@v3
with:
registry: "${{ vars.DOCKER_REGISTRY }}"
username: "${{ secrets.DOCKER_USERNAME }}"
password: "${{ secrets.DOCKER_PASSWORD }}"

- name: Build image
run: docker build docfx --file "docfx/Dockerfile" -t ${{ vars.DOCKER_REGISTRY }}/docfx:${{ env.docfxVersion }}

- name: Push image
run: docker push ${{ vars.DOCKER_REGISTRY }}/docfx:${{ env.docfxVersion }}
32 changes: 32 additions & 0 deletions .github/workflows/pr-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Delete a preview environment

on:
pull_request:
types: [closed]

env:
SLOT_NAME: pr-${{ github.event.number }}

jobs:
delete-slot:
runs-on: ubuntu-latest

steps:
- name: Log into Azure CLI with service principal
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

- name: Delete slot on staging site
run: az webapp deployment slot delete --resource-group ${{ vars.AZURE_RESOURCE_GROUP }} --name ${{ vars.AZURE_WEBAPP_NAME}} --slot ${{ env.SLOT_NAME }}

delete-deployment:
runs-on: ubuntu-latest

steps:
- name: Delete Deployment Environment
uses: strumwolf/delete-deployment-environment@v2
with:
environment: "pr-${{ github.event.number }}"
token: ${{ secrets.GITHUB_TOKEN }}
onlyRemoveDeployments: true
22 changes: 22 additions & 0 deletions .github/workflows/stage-prod-swap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Swap staging slot contents into production

on:
workflow_dispatch:

jobs:
promote-to-production:
name: Promote to production
runs-on: ubuntu-latest
environment:
name: 'Production'
url: 'https://${{ vars.AZURE_WEBAPP_NAME }}.azurewebsites.net/'

steps:
- name: Log into Azure CLI with service principal
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

- name: Swap slots
run: az webapp deployment slot swap -s ${{ vars.STAGING_SLOT_NAME }} -n ${{ vars.AZURE_WEBAPP_NAME }} -g ${{ vars.AZURE_RESOURCE_GROUP }}

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/api/browser/**/*.manifest
/api/browser/**/*.yml
/obj/
/build/
/sources/
/_site/
/tools/
/.vscode/
/.vs/
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM steeltoe.azurecr.io/documentation-metadata:3.2.0-2.5.5-6 AS build
FROM steeltoe.azurecr.io/documentation-metadata:2.5.5-3.2.6 AS build
WORKDIR /docs
COPY . .
RUN docfx build -o build --globalMetadataFiles host.json
RUN docfx build -o /built-docs --globalMetadataFiles main-site.json

FROM nginx:1.19
RUN rm -rf /usr/share/nginx/html
COPY --from=build /docs/build/_site /usr/share/nginx/html
COPY --from=build /built-docs/_site /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY docker/ /
COPY *.env /etc/documentation-site/
3 changes: 2 additions & 1 deletion Dockerfile-metadata
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM steeltoe.azurecr.io/docfx:2.57.2-11
FROM steeltoe.azurecr.io/docfx:2.59.2
WORKDIR /docs
COPY . .
RUN ["chmod", "+x", "./build-metadata.sh"]
RUN ./build-metadata.sh
1 change: 0 additions & 1 deletion Production.env

This file was deleted.

Loading

0 comments on commit acc12e9

Please sign in to comment.