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

Add deploy to dev and staging #156

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/workflows/deploy_to_development.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Deploy to Development

# Only one workflow in a concurrency group may run at a time
concurrency:
group: development-concurrency
cancel-in-progress: true

on:
push:
branches:
- "main"

jobs:
trigger-github-deployment:
name: Trigger GitHub Deployment
environment: Development
runs-on: ubuntu-latest
steps:
- name: Empty Step
run: echo "Hello World"

get-short-sha:
needs: trigger-github-deployment
outputs:
tag: ${{ steps.get-tag.outputs.tag }}
runs-on: ubuntu-latest
steps:
- id: get-tag
run: |
SHA_SHORT=$(echo ${{ github.sha }} | cut -c1-8)
echo "tag=$SHA_SHORT" >> "$GITHUB_OUTPUT"

build-and-push-components:
name: Build and push containers to ghcr for Development
needs: [get-short-sha, trigger-github-deployment]
uses: ./.github/workflows/publish_component.yml
with:
Registry: ghcr.io
ImageName: ${{ github.repository }}
Tag: ${{ needs.get-short-sha.outputs.tag }}
secrets:
RegistryUsername: ${{ github.actor }}
RegistryPassword: ${{ secrets.GITHUB_TOKEN }}

deploy:
name: Update deployment in Development
needs: [build-and-push-components, get-short-sha, trigger-github-deployment]
uses: ./.github/workflows/update_aurora_deployment.yml
with:
Environment: development
Registry: ghcr.io
ImageName: ${{ github.repository }}
Tag: ${{ needs.get-short-sha.outputs.tag }}
AuthorEmail: ${{ github.event.head_commit.author.email }}
AuthorName: ${{ github.event.head_commit.author.name }}
secrets:
DeployKey: ${{ secrets.ROBOTICS_INFRASTRUCTURE_DEPLOY_KEY }}
56 changes: 56 additions & 0 deletions .github/workflows/deploy_to_staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Deploy to Staging

# Only one workflow in a concurrency group may run at a time
concurrency:
group: staging-concurrency
cancel-in-progress: true

on:
release:
types: [published]

jobs:
trigger-github-deployment:
name: Trigger GitHub Deployment
environment: Staging
runs-on: ubuntu-latest
steps:
- name: Empty Step
run: echo "Hello World"

build-and-push-release-to-dev:
name: Update container in dev with version tag
needs: trigger-github-deployment
uses: ./.github/workflows/publish_component.yml
with:
Registry: auroradevacr.azurecr.io
ImageName: robotics/isar-turtlebot
Tag: ${{ github.event.release.tag_name }}
secrets:
RegistryUsername: ${{ secrets.ROBOTICS_ACRPUSH_DOCKER_APPLICATION_ID }}
RegistryPassword: ${{ secrets.ROBOTICS_ACRPUSH_DOCKER_SECRET }}

build-and-push-components:
name: Build and push container to auroraprodcr for Staging/Production
needs: [trigger-github-deployment]
uses: ./.github/workflows/publish_component.yml
with:
Registry: auroraprodacr.azurecr.io
ImageName: robotics/isar-turtlebot
Tag: ${{ github.event.release.tag_name }}
secrets:
RegistryUsername: ${{ secrets.ROBOTICS_ACRPUSH_DOCKER_APPLICATION_ID }}
RegistryPassword: ${{ secrets.ROBOTICS_ACRPUSH_DOCKER_SECRET }}

deploy:
name: Update deployment in Staging
needs: [trigger-github-deployment, build-and-push-components]
uses: ./.github/workflows/update_aurora_deployment.yml
with:
Environment: staging
Registry: auroraprodacr.azurecr.io
ImageName: robotics/isar-turtlebot
Tag: ${{ github.event.release.tag_name }}
AuthorName: ${{ github.event.release.author.login }}
secrets:
DeployKey: ${{ secrets.ROBOTICS_INFRASTRUCTURE_DEPLOY_KEY }}
52 changes: 52 additions & 0 deletions .github/workflows/publish_component.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Build and publish component

on:
workflow_call:
inputs:
Registry:
required: true
type: string
Tag:
required: true
type: string
ImageName:
required: true
type: string
secrets:
RegistryUsername:
required: true
RegistryPassword:
required: true

jobs:
build-and-push-container:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Log in to the Github Container registry
uses: docker/login-action@v2
with:
registry: ${{ inputs.Registry }}
username: ${{ secrets.RegistryUsername }}
password: ${{ secrets.RegistryPassword }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ inputs.Registry }}/${{ inputs.ImageName }}

- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
push: true
tags: |
${{ inputs.Registry }}/${{ inputs.ImageName }}:${{ inputs.Tag }}
${{ inputs.Registry }}/${{ inputs.ImageName }}:latest
labels: ${{ steps.meta.outputs.labels }}
58 changes: 58 additions & 0 deletions .github/workflows/update_aurora_deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Update deployment in aurora

on:
workflow_call:
inputs:
Environment:
required: true
type: string
Tag:
required: true
type: string
Registry:
required: true
type: string
ImageName:
required: true
type: string
AuthorEmail:
required: false
type: string
AuthorName:
required: true
type: string
secrets:
DeployKey:
required: true

jobs:
deploy:
name: Update deployment
runs-on: ubuntu-latest
env:
EMAIL: ${{ inputs.AuthorEmail }}
NAME: ${{ inputs.AuthorName }}
steps:
- name: Checkout infrastructure
uses: actions/checkout@v3
with:
ref: main
repository: equinor/robotics-infrastructure
ssh-key: ${{ secrets.DeployKey }}

- name: Update image in file
run: |
LINE_NUMBERS=($(grep -n "${{ inputs.Registry }}/${{ inputs.ImageName }}" k8s_kustomize/overlays/${{ inputs.Environment }}/kustomization.yaml | cut -d ':' -f 1))
for line_number in "${LINE_NUMBERS[@]}"
do
TAG_LINE_NUMBER=$((line_number+1))
sed -i "${TAG_LINE_NUMBER} s/newTag:.*/newTag: ${{ inputs.Tag }}/" "k8s_kustomize/overlays/${{ inputs.Environment }}/kustomization.yaml"
done

- name: Update infrastructure in GitHub
run: |
git config --global user.email "${EMAIL}"
git config --global user.name "GitHub Actions (${NAME})"
git add k8s_kustomize/overlays/${{ inputs.Environment }}/kustomization.yaml
git commit --message "GHA: Update Isar-Turtlebot in ${{ inputs.Environment }} (${{ inputs.Tag }})" || true
git push
Loading