Skip to content

Commit

Permalink
Merge 22bdf91 into ebf1da3
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterShipstoneAND authored May 31, 2023
2 parents ebf1da3 + 22bdf91 commit 85b87c5
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 4 deletions.
132 changes: 132 additions & 0 deletions .github/workflows/build-and-push-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
name: Build & deploy to environment

on:
pull_request:

workflow_dispatch:
inputs:
environment:
type: environment
description: "Choose an environment to deploy to"
required: true

concurrency:
group: ${{ github.workflow }}-${{ github.event.inputs.environment }}

env:
DOCKER_IMAGE: plan-tech-app
NODE_VERSION: 18.x

jobs:
set-env:
name: Determine environment
runs-on: ubuntu-22.04
outputs:
environment: ${{ steps.var.outputs.environment }}
branch: ${{ steps.var.outputs.branch }}
release: ${{ steps.var.outputs.release }}
checked-out-sha: ${{ steps.var.outputs.checked-out-sha }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.ref }}

- id: var
run: |
GIT_REF=${{ github.ref }}
GIT_BRANCH=${GIT_REF##*/}
INPUT=${{ github.event.inputs.environment }}
ENVIRONMENT=${INPUT:-"dev"}
RELEASE=${ENVIRONMENT,,}-`date +%Y-%m-%d`.${{ github.run_number }}
CHECKED_OUT_SHA="$(git log -1 '--format=format:%H')"
echo "environment=${ENVIRONMENT,,}" >> $GITHUB_OUTPUT
echo "branch=$GIT_BRANCH" >> $GITHUB_OUTPUT
echo "release=${RELEASE}" >> $GITHUB_OUTPUT
echo "checked-out-sha=${CHECKED_OUT_SHA}" >> $GITHUB_OUTPUT
build-and-push-image:
name: Build and push to ACR
needs: set-env
runs-on: ubuntu-22.04
environment: ${{ needs.set-env.outputs.environment }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.ref }}

- name: Azure Container Registry login
uses: docker/login-action@v2
with:
username: ${{ secrets.AZ_CLIENT_ID }}
password: ${{ secrets.AZ_CLIENT_SECRET }}
registry: ${{ secrets.AZ_ACR_URL }}

- name: Build and push docker image
uses: docker/build-push-action@v3
with:
context: ./src/
file: ./src/Dfe.PlanTech.Web/Dockerfile
build-args: COMMIT_SHA=${{ needs.set-env.outputs.checked-out-sha }}
tags: |
${{ secrets.AZ_ACR_URL }}/${{ env.DOCKER_IMAGE }}:${{ needs.set-env.outputs.branch }}
${{ secrets.AZ_ACR_URL }}/${{ env.DOCKER_IMAGE }}:${{ needs.set-env.outputs.release }}
${{ secrets.AZ_ACR_URL }}/${{ env.DOCKER_IMAGE }}:sha-${{ needs.set-env.outputs.checked-out-sha }}
${{ secrets.AZ_ACR_URL }}/${{ env.DOCKER_IMAGE }}:latest
push: true

create-tag:
name: Tag and release
needs: set-env
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.ref }}

- name: Create tag
run: |
git tag ${{ needs.set-env.outputs.release }}
git push origin ${{ needs.set-env.outputs.release }}
- name: Create release
uses: "actions/github-script@v6"
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
script: |
try {
await github.rest.repos.createRelease({
draft: ${{ needs.set-env.outputs.environment == 'staging' }},
generate_release_notes: true,
name: "${{ needs.set-env.outputs.release }}",
owner: context.repo.owner,
prerelease: ${{ needs.set-env.outputs.environment == 'staging' }},
repo: context.repo.repo,
tag_name: "${{ needs.set-env.outputs.release }}",
});
} catch (error) {
core.setFailed(error.message);
}
deploy-image:
name: Deploy to ${{ needs.set-env.outputs.environment }} (${{ needs.set-env.outputs.release }})
needs: [ build-and-push-image, set-env ]
runs-on: ubuntu-22.04
environment: ${{ needs.set-env.outputs.environment }}
steps:
- name: Azure login with ACA credentials
uses: azure/login@v1
with:
creds: '{"clientId":"${{ secrets.AZ_CLIENT_ID }}","clientSecret":"${{ secrets.AZ_CLIENT_SECRET }}","subscriptionId":"${{ secrets.AZ_SUBSCRIPTION_ID }}","tenantId":"${{ secrets.AZ_TENANT_ID }}"}'

- name: Update Azure Container Apps Revision
uses: azure/CLI@v1
id: azure
with:
azcliversion: 2.45.0
inlineScript: |
az config set extension.use_dynamic_install=yes_without_prompt
az containerapp update \
--name ${{ secrets.AZ_ACA_NAME }} \
--resource-group ${{ secrets.AZ_ACA_RESOURCE_GROUP }} \
--image ${{ secrets.AZ_ACR_URL }}/${{ env.DOCKER_IMAGE }}:${{ needs.set-env.outputs.release }} \
--output none
4 changes: 2 additions & 2 deletions src/Dfe.PlanTech.Web/Controllers/PagesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public PagesController(ILogger<PagesController> logger)

public async Task<IActionResult> Index([FromServices] GetPageQuery getPageQuery)
{
var page = await getPageQuery.GetPageBySlug(nameof(Pages.Landing));
//ar page = await getPageQuery.GetPageBySlug(nameof(Pages.Landing));

return View("LandingPage", page);
return View("LandingPage", new Domain.Content.Models.Page() );
}

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
Expand Down
2 changes: 1 addition & 1 deletion src/Dfe.PlanTech.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
builder.Services.AddControllersWithViews();
builder.Services.AddGovUkFrontend();

builder.Services.SetupContentfulClient(builder.Configuration, "Contentful");
// builder.Services.SetupContentfulClient(builder.Configuration, "Contentful");

builder.Services.AddScoped((_) => new TextRendererOptions(new List<MarkOption>() {
new MarkOption(){
Expand Down
4 changes: 3 additions & 1 deletion terraform/main-hosting.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ module "main_hosting" {
tags = local.tags

enable_container_registry = true
image_name = "plan-tech"
image_name = "plan-tech-app"

enable_cdn_frontdoor = true
}

0 comments on commit 85b87c5

Please sign in to comment.