[ImgBot] Optimize images #18
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
--- | |
# This workflow will build a docker container, publish it to Azure Container Registry, and deploy it to Azure Kubernetes Service. | |
# | |
# To configure this workflow: | |
# | |
# 1. Set up the following secrets in your workspace: | |
# a. REGISTRY_USERNAME with ACR username | |
# b. REGISTRY_PASSWORD with ACR Password | |
# c. AZURE_CREDENTIALS with the output of `az ad sp create-for-rbac --sdk-auth` | |
# | |
# 2. Change the values for the REGISTRY_NAME, CLUSTER_NAME, CLUSTER_RESOURCE_GROUP and NAMESPACE environment variables (below). | |
name: docker-acr-aks-manifest-new | |
on: | |
push: | |
# Environment variables available to all jobs and steps in this workflow | |
env: | |
REGISTRY_NAME: acr4ravigadhia | |
CLUSTER_NAME: cluster-aks-demo-2 | |
CLUSTER_RESOURCE_GROUP: rg-aks-demo | |
NAMESPACE: default | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@master | |
# Connect to Azure Container registry (ACR) | |
- uses: azure/docker-login@v1 | |
with: | |
login-server: ${{ env.REGISTRY_NAME }}.azurecr.io | |
username: ${{ secrets.REGISTRY_USERNAME }} | |
password: ${{ secrets.REGISTRY_PASSWORD }} | |
# Container build and push to a Azure Container registry (ACR) | |
- run: | | |
docker build . -t ${{ env.REGISTRY_NAME }}.azurecr.io/sample_rails_app_docker:${{ github.sha }} | |
docker push ${{ env.REGISTRY_NAME }}.azurecr.io/sample_rails_app_docker:${{ github.sha }} | |
# Set the target Azure Kubernetes Service (AKS) cluster. | |
- uses: azure/aks-set-context@v1 | |
with: | |
creds: '${{ secrets.AZURE_CREDENTIALS }}' | |
cluster-name: ${{ env.CLUSTER_NAME }} | |
resource-group: ${{ env.CLUSTER_RESOURCE_GROUP }} | |
# Create namespace if doesn't exist | |
- run: | | |
kubectl create namespace ${{ env.NAMESPACE }} --dry-run -o json | kubectl apply -f - | |
# Create imagepullsecret for Azure Container registry (ACR) | |
- uses: azure/k8s-create-secret@v1 | |
with: | |
container-registry-url: ${{ env.REGISTRY_NAME }}.azurecr.io | |
container-registry-username: ${{ secrets.REGISTRY_USERNAME }} | |
container-registry-password: ${{ secrets.REGISTRY_PASSWORD }} | |
secret-name: ${{ env.REGISTRY_NAME }}-registry-connection | |
namespace: ${{ env.NAMESPACE }} | |
# Deploy app to AKS | |
- uses: azure/k8s-deploy@v1 | |
with: | |
manifests: | | |
manifests/all-in-one.yaml | |
images: | | |
${{ env.REGISTRY_NAME }}.azurecr.io/sample_rails_app_docker:${{ github.sha }} | |
imagepullsecrets: | | |
${{ env.REGISTRY_NAME }}-registry-connection | |
namespace: ${{ env.NAMESPACE }} |