Fix spelling #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy to environment | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- '**.sh' | |
- 'Dockerfile' | |
workflow_dispatch: | |
inputs: | |
environment: | |
type: environment | |
description: "Choose an environment to deploy to" | |
required: true | |
jobs: | |
set-env: | |
name: Set environment variables | |
runs-on: ubuntu-22.04 | |
outputs: | |
github_repository_lc: ${{ steps.var.outputs.github_repository_lc }} | |
environment: ${{ steps.var.outputs.environment }} | |
steps: | |
- id: var | |
run: | | |
INPUT=${{ github.event.inputs.environment }} | |
ENVIRONMENT=${INPUT:-"development"} | |
GITHUB_REPOSITORY=${{ github.repository }} | |
echo "environment=${ENVIRONMENT,,}" >> $GITHUB_OUTPUT | |
echo "github_repository_lc=${GITHUB_REPOSITORY,,}" >> $GITHUB_OUTPUT | |
build-and-push-image: | |
name: Build and push to GHCR | |
runs-on: ubuntu-22.04 | |
needs: set-env | |
environment: ${{ needs.set-env.outputs.environment }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.ref }} | |
- name: GitHub Container Registry login | |
uses: docker/#-action@v3 | |
with: | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
registry: ghcr.io | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build and push docker image | |
uses: docker/build-push-action@v5 | |
with: | |
tags: ghcr.io/${{ needs.set-env.outputs.github_repository_lc }}:latest | |
push: true | |
cache-from: type=gha | |
acr-import: | |
name: Import image to ${{ needs.set-env.outputs.environment }} ACR | |
needs: [ build-and-push-image, set-env ] | |
runs-on: ubuntu-22.04 | |
environment: ${{ needs.set-env.outputs.environment }} | |
steps: | |
- name: Azure login with ACR credentials | |
uses: azure/#@v2 | |
with: | |
creds: ${{ secrets.ACR_CREDENTIALS }} | |
- name: Run ACR Import | |
uses: azure/cli@v2 | |
with: | |
inlineScript: | | |
az acr import \ | |
--name ${{ secrets.ACR_NAME }} \ | |
--source "ghcr.io/${{ needs.set-env.outputs.github_repository_lc }}:latest" \ | |
--image "rsd-kv-secret-scanner:latest" \ | |
--username ${{ github.actor }} \ | |
--password ${{ secrets.GITHUB_TOKEN }} \ | |
--force | |
deploy: | |
name: Deploy new image | |
needs: [ acr-import ] | |
runs-on: ubuntu-22.04 | |
environment: ${{ needs.set-env.outputs.environment }} | |
steps: | |
- name: Azure login with ACI credentials | |
uses: azure/#@v2 | |
with: | |
creds: ${{ secrets.ACI_CREDENTIALS }} | |
- name: Restart Container | |
uses: azure/cli@v2 | |
with: | |
inlineScript: | | |
az container restart \ | |
--name ${{ secrets.CONTAINER_NAME }} \ | |
--resource-group ${{ secrets.RESOURCE_GROUP }} |