Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
use GitHub Actions to build and deploy image
Browse files Browse the repository at this point in the history
  • Loading branch information
Xtrah committed Sep 11, 2024
1 parent 348aa4f commit 2c068ed
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 42 deletions.
27 changes: 22 additions & 5 deletions .github/workflows/build-push-docker.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
name: Build and Push to ACR

on:
push:
branches:
- 'main'
- main
workflow_dispatch:

jobs:
build:
name: 'Build and Push to ACR'
Expand All @@ -13,16 +16,30 @@ jobs:
shell: bash

steps:
- uses: actions/checkout@v4
- name: Checkout code
uses: actions/checkout@v4

- uses: docker/login-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
registry: ${{ secrets.DOCKER_REGISTRY_SERVER_URL }}
username: ${{ secrets.DOCKER_REGISTRY_SERVER_USERNAME }}
password: ${{ secrets.DOCKER_REGISTRY_SERVER_PASSWORD }}

- uses: docker/build-push-action@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push Docker image to ACR
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ secrets.DOCKER_REGISTRY_SERVER_URL }}/kantega-big-agi:latest
file: Dockerfile

- name: Deploy to Azure Web App
uses: azure/webapps-deploy@v3
with:
app-name: 'kantega-big-agi'
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
images: '${{ secrets.DOCKER_REGISTRY_SERVER_URL }}/kantega-big-agi:latest'
34 changes: 0 additions & 34 deletions infra/build.tf
Original file line number Diff line number Diff line change
@@ -1,34 +0,0 @@
resource "null_resource" "docker_build" {
triggers = {
always_run = "${timestamp()}"
}

provisioner "local-exec" {
command = <<EOT
cd "${path.module}/.."
az acr login --name ${azurerm_container_registry.acr.name} || exit 1
if ! docker version > /dev/null 2>&1; then
echo "Docker is not running. Please start Docker and try again."
exit 1
fi
# Create a temporary Buildx builder with docker-container driver
BUILDER_NAME=temp-builder-$(date +%s)
docker buildx create --name $BUILDER_NAME --use --driver docker-container
# Remove existing images
docker image remove ${azurerm_container_registry.acr.login_server}/${var.project_name}:latest || true
az acr repository delete --name ${azurerm_container_registry.acr.name} --image ${var.project_name}:latest --yes || true
# Build and push big-agi image
docker buildx build --platform linux/amd64,linux/arm64 -t ${azurerm_container_registry.acr.login_server}/${var.project_name}:latest --push .
# Clean up the temporary builder
docker buildx rm $BUILDER_NAME
EOT
}

depends_on = [azurerm_container_registry.acr]
}
9 changes: 6 additions & 3 deletions infra/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ resource "azurerm_linux_web_app" "browserless" {
identity {
type = "SystemAssigned"
}
depends_on = [
azurerm_service_plan.asp,
]

depends_on = [null_resource.docker_build]
}

resource "azurerm_linux_web_app" "app" {
Expand Down Expand Up @@ -141,7 +143,8 @@ resource "azurerm_linux_web_app" "app" {
}

depends_on = [
null_resource.docker_build,
azurerm_linux_web_app.browserless
azurerm_service_plan.asp,
azurerm_linux_web_app.browserless,
azurerm_container_registry.acr
]
}

0 comments on commit 2c068ed

Please sign in to comment.