Skip to content

Commit 0520eee

Browse files
authored
Update Pipeline to create and push docker image (#61)
# Why is this change being made? So we can automatically generate docker images and push them to a container registry. # What changed? - Updated the pipeline to have: - A task to get the build start time for the tag of the docker image. - A buildAndPush task which creates and pushes an image to docker hub. We're currently using my private docker hub while we figure out where we want these images to be pushed. - Updated the documentation to fix some errors and added some information on how to use these new docker images. - Changed DockerFile copy path from Debug to Release since the pipeline builds release. Not in this PR: - Added a service connection so the Azure pipeline can communicate with the dockerhub from this pipeline config. # How was this validated? Created a duplicate pipeline for my fork of this repo. I then validated by creating a commit that the image ended up on the docker hub and followed the instructions that I added to validate that the container could be run.
1 parent f2c6cc1 commit 0520eee

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
FROM mcr.microsoft.com/dotnet/sdk:5.0
66
# TODO once we have a story for release process, change this to release
7-
COPY Cosmos.GraphQL.Service/Cosmos.GraphQL.Service/bin/Debug/net5.0 /App
7+
COPY Cosmos.GraphQL.Service/Cosmos.GraphQL.Service/bin/Release/net5.0 /App
88
WORKDIR /App
99
ENV ASPNETCORE_URLS=http://+:5000
1010
ENTRYPOINT ["dotnet", "Cosmos.GraphQL.Service.dll"]

build-pipelines.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,25 @@ steps:
4949
command: test
5050
projects: '**/*Tests/*.csproj'
5151
arguments: '--filter "TestCategory!=Cosmos&TestCategory!=MsSql" --configuration $(buildConfiguration)'
52+
53+
# This task gets the current date and saves it to a variable so the docker task can use the build's
54+
# date and time as a tag.
55+
- task: PowerShell@2
56+
displayName: "Get date for Docker image Tag"
57+
inputs:
58+
targetType: 'inline'
59+
script: |
60+
Write-Host "Setting up the date and time as a build variable for the Docker tag"
61+
$date=$(Get-Date -format yyyyMMdd-HHmmss)
62+
Write-Host "##vso[task.setvariable variable=BuildDate]$date"
63+
64+
# Build a docker image and push it to the container registry. This is a temporary location until
65+
# we close on where we want these images to live.
66+
- task: Docker@2
67+
displayName: "Build and push docker image to docker hub"
68+
inputs:
69+
containerRegistry: 'CosmosDB-GraphQL-TempDockerHub'
70+
repository: 'matrembl/graphql'
71+
command: 'buildAndPush'
72+
Dockerfile: '**/Dockerfile'
73+
tags: '$(BuildDate)-$(Build.SourceVersion)' # Use build date and commitId as the tag for the image

docs/GetStarted.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
# Introduction
22

3+
# Deploy docker container from DockerHub (Prebuilt image)
4+
N.B. This section only applies if you want to use a prebuilt image, if you want to build it yourself, move on to the next section (Build and deploy as Docker Container)
35

4-
# Deploy as Docker Container
6+
N.B. The image is currently hosted in a temporary location, so you might not have access to it.
7+
8+
1. Pull the docker image:
9+
```bash
10+
docker pull matrembl/graphql:20211019-154145 # Note to update to the correct tag
11+
```
12+
2. Update the config.json and the appsettings.json files with your connection strings and the resolvers
13+
14+
3. Launch the docker container and map the config.json and appsettings.json files. The command should look something like this (depending on the path to your appsettings and config files, and the image you are using):
15+
16+
```bash
17+
docker run --mount type=bind,source="$(pwd)\Cosmos.GraphQL.Service\Cosmos.GraphQL.Service\appsettings.json",target="/App/appsettings.json" --mount type=bind,source="$(pwd)\Cosmos.GraphQL.Service\Cosmos.GraphQL.Service\config.json",target="/App/config.json" -d -p 5000:5000 matrembl/graphql:20211019-154145
18+
# Note to update to the correct tag
19+
```
20+
4. The container should be accessible at localhost:5000
21+
22+
# Build and deploy as Docker Container
523

624
## Build Image
725

@@ -48,9 +66,9 @@ docker tag multiverse-datagateway multiverseacr.azurecr.io/multiverse-datagatewa
4866
Login to the ACR with the correct credentials
4967
```bash
5068
docker login multiverseacr.azurecr.io
51-
````
69+
```
5270

5371
Push the retagged image
5472
```bash
5573
docker push multiverseacr.azurecr.io/multiverse-datagateway
56-
``
74+
```

0 commit comments

Comments
 (0)