Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
frozen
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CSE6
frozen
Commits
8fd2f105
Commit
8fd2f105
authored
2 years ago
by
Arno Wunderlich
Browse files
Options
Downloads
Patches
Plain Diff
modify gitlab-ci-yml
parent
d4027338
No related branches found
No related tags found
1 merge request
!30
Add staging stage
Pipeline
#14917
failed
2 years ago
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
.gitlab-ci.yml
+78
-1
78 additions, 1 deletion
.gitlab-ci.yml
with
78 additions
and
1 deletion
.gitlab-ci.yml
+
78
−
1
View file @
8fd2f105
...
...
@@ -2,6 +2,7 @@
stages
:
-
build
-
test
-
staging
-
deploy
variables
:
...
...
@@ -66,7 +67,62 @@ test:
-
echo "Test were run succesfully!"
## Deploy latest image to the production
deploy
:
deploy to staging
:
stage
:
staging
## Only run this stage when main branch receives changes.
only
:
-
main
## Use microsoft provided azure cli image, that contains az cli.
image
:
mcr.microsoft.com/azure-cli
## Setup the environment variables. The can be accessed through the gitlab
## Deployments -> Environments. Generates url based on the app and branch name.
environment
:
name
:
$CI_JOB_STAGE
url
:
https://${AZURE_APP_NAME}-${CI_ENVIRONMENT_SLUG}.azurewebsites.net
before_script
:
## Make sanity check that gitlab variables stage is done.
-
test -z "${AZURE_SP_NAME}" && (echo "Missing required variable AZURE_SP_NAME. See 'Staging.md'"; exit 1)
-
test -f "${AZURE_SP_CERT}" || ( echo "AZURE_SP_CERT (${AZURE_SP_CERT}) file is missing!"; exit 1)
-
test -z "${AZURE_APP_NAME}" && (echo "Missing required variable AZURE_APP_NAME. See 'Staging.md'"; exit 1)
-
test -z "${AZURE_RESOURCE_GROUP}" && (echo "Missing required variable DOCKER_AUTH_CONFIG. See 'Staging.md'"; exit 1)
## Login into azure
-
az login --service-principal -u "${AZURE_SP_NAME}" -p "${AZURE_SP_CERT}" --tenant "jyu.onmicrosoft.com"
script
:
## Create staging slot and copy settings from production
-
|
az webapp deployment slot create -n "$AZURE_APP_NAME" -g "$AZURE_RESOURCE_GROUP" \
--slot "$CI_ENVIRONMENT_SLUG" --configuration-source "$AZURE_APP_NAME"
## TODO: Create a snapshot of database, and use it.
## If you need to change settings see: https://docs.microsoft.com/en-us/cli/azure/webapp/config/appsettings
## Change container tag to reflect branch we're running on
-
|
az webapp config container set -n "$AZURE_APP_NAME" -g "$AZURE_RESOURCE_GROUP" \
--docker-custom-image-name "${DOCKER_IMAGE_NAME}:${DOCKER_TAG}" -s "$CI_ENVIRONMENT_SLUG"
## In case slot already existed, restart the slot
-
az webapp restart -n "$AZURE_APP_NAME" -g "$AZURE_RESOURCE_GROUP" -s "$CI_ENVIRONMENT_SLUG"
## Restart is not immediate, it takes a sec or two, depending on container changes.
-
sleep
20
## Store server info as artifact for prosperity
-
curl "$CI_ENVIRONMENT_URL/server-info" -o server-info.json
artifacts
:
paths
:
-
server-info.json
## Push latest image into registry with the `latest` tag.
docker tag latest
:
stage
:
deploy
environment
:
production
image
:
docker:20.10.23
...
...
@@ -78,3 +134,24 @@ deploy:
## Add the `latest` tag to the image we have build.
-
docker buildx imagetools create ${DOCKER_IMAGE_NAME}:${DOCKER_TAG} --tag ${DOCKER_IMAGE_NAME}:latest
## Swap the production and staging slots around.
staging to production
:
stage
:
deploy
## Only run this stage when main branch receives changes.
only
:
-
main
## Use microsoft provided azure cli image, that contains az cli.
image
:
mcr.microsoft.com/azure-cli
environment
:
name
:
production
url
:
https://${AZURE_APP_NAME}.azurewebsites.net/
before_script
:
## Login into azure
-
az login --service-principal -u "${AZURE_SP_NAME}" -p "${AZURE_SP_CERT}" --tenant "jyu.onmicrosoft.com"
script
:
## Swap production and staging slots.
-
az webapp deployment slot swap -g "$AZURE_RESOURCE_GROUP" -n "$AZURE_APP_NAME" -s staging --target-slot production
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment