Skip to content
bitovi

GitHub Action

Deploy Docker to Azure VM

v1.0.1 Latest version

Deploy Docker to Azure VM

bitovi

Deploy Docker to Azure VM

Deploy a Docker app to an Azure VM with Docker Compose

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Deploy Docker to Azure VM

uses: bitovi/[email protected]

Learn more about this action in bitovi/github-actions-docker-to-azure-vm

Choose a version

Docker to Azure VM

GitHub action to deploy any Docker-based app to an Azure VM using Docker and Docker Compose.

The action will copy this repo to the VM and then run docker-compose up. alt

Getting Started Intro Video

Coming Soon

Requirements

  1. Files for Docker
  2. An Azure account

1. Files for Docker

Your app needs a Dockerfile and a docker-compose.yaml file.

For more details on setting up Docker and Docker Compose, check out Bitovi's Academy Course: Learn Docker

2. An Azure account

You'll need Access Secrets from an Azure account. The best documentation on how to get started from a command-line perspective is here: https://learn.microsoft.com/en-us/cli/azure/authenticate-azure-cli and https://learn.microsoft.com/en-us/cli/azure/manage-azure-subscriptions-azure-cli

Environment variables

For environment variables in your app, you can provide:

  • repo_env - A file in your repo that contains env vars
  • ghv_env - An entry in Github actions variables
  • dot_env - An entry in Github secrets
  • Azure_secret_env - The path to a JSON format secret in Azure

Then hook it up in your docker-compose.yaml file like:

version: '3.9'
services:
  app:
    env_file: .env

These environment variables are merged to the .env file quoted in the following order:

  • Terraform passed env vars ( This is not optional nor customizable )
  • Repository checked-in env vars - repo_env file as default. (KEY=VALUE style)
  • Github Secret - Create a secret named DOT_ENV - (KEY=VALUE style)
  • Azure Secret - JSON style like '{"key":"value"}'

Example usage

Create .github/workflow/deploy.yaml with the following to build on push:

Basic example

name: Basic deploy
on:
  push:
    branches: [ main ]

jobs:
  Deploy:
    runs-on: ubuntu-latest
    steps:
      - id: deploy
        uses: bitovi/github-actions-docker-to-azure-vm@v1
        with:
          AZURE_ARM_CLIENT_ID: ${{ secrets.AZURE_ARM_CLIENT_ID }}
          AZURE_ARM_CLIENT_SECRET: ${{ secrets.AZURE_ARM_CLIENT_SECRET }}
          AZURE_ARM_TENANT_ID: ${{ secrets.AZURE_ARM_TENANT_ID }}
          AZURE_ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_ARM_SUBSCRIPTION_ID }}
          azure_resource_identifier: 'my-resource-group'
          AZURE_STORAGE_ACCOUNT: 'mystorageaccount'
          tf_state_bucket: 'my-state-bucket'
          stack_destroy: 'false'

Advanced example

name: Advanced deploy
on:
  push:
    branches: [ main ]

permissions:
  contents: read

jobs:
  EC2-Deploy:
    runs-on: ubuntu-latest
    environment:
      name: ${{ github.ref_name }}
      url: ${{ steps.deploy.outputs.vm_url }}
    steps:
    - id: deploy
      name: Deploy
      uses: bitovi/github-actions-docker-to-azure-vm@v1
      with:
        AZURE_ARM_CLIENT_ID: ${{ secrets.AZURE_ARM_CLIENT_ID }}
        AZURE_ARM_CLIENT_SECRET: ${{ secrets.AZURE_ARM_CLIENT_SECRET }}
        AZURE_ARM_TENANT_ID: ${{ secrets.AZURE_ARM_TENANT_ID }}
        AZURE_ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_ARM_SUBSCRIPTION_ID }}
        Azure_default_region: eastus
        tf_state_bucket: 'my-state-bucket'
        dot_env: ${{ secrets.DOT_ENV }}
        ghv_env: ${{ vars.VARS }}
        app_port: 3000
        additional_tags: "{\"key1\": \"value1\",\"key2\": \"value2\"}"

Need help or have questions?

This project is supported by Bitovi, a DevOps Consultancy and a proud supporter of Open Source software.

You can get help or ask questions on our Discord channel! Come hang out with us!

Or, you can hire us for training, consulting, or development. Set up a free consultation.

Made with BitOps

BitOps allows you to define Infrastructure-as-Code for multiple tools in a central place. This action uses a BitOps Operations Repository to set up the necessary Terraform and Ansible to create infrastructure and deploy to it.

Contributing

We would love for you to contribute to this repo!

Would you like to see additional features? Create an issue or feel free to branch and submit a PR! We love discussing newsolutions!

License

The scripts and documentation in this project are released under the MIT License.