From ee52b0f2f4676047c7ed4a00201a5ea1eb08bb3e Mon Sep 17 00:00:00 2001 From: Hoan Nguyen <83745591+nqhoan-axonivy@users.noreply.github.com> Date: Tue, 23 Jul 2024 22:40:38 +0700 Subject: [PATCH] Feature/MARP-224 Create dockerfile for deployment marketplace homepage (#56) - Added clean-up docker container and images - Added waiting for containers to start before tagging --- .github/workflows/docker-build.yml | 23 ++++++++++++++++++----- .github/workflows/docker-release.yml | 21 +++++++++++++++++++++ marketplace-build/config/nginx/nginx.conf | 4 ++++ 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index bbe173702..694dcc597 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -7,11 +7,25 @@ on: workflow_call: jobs: - build: + cleanup: + name: Clean up docker container and images runs-on: self-hosted steps: - - uses: actions/checkout@v4 + - name: Bring down and remove containers and images + working-directory: ./marketplace-build + run: | + docker compose down --rmi all + + build-and-deploy: + name: Build and bring up docker containers + runs-on: self-hosted + needs: cleanup + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Update environment variables for .env env: ENV_FILE: './marketplace-build/.env' @@ -33,8 +47,7 @@ jobs: sed -i "s/^MARKET_GITHUB_TOKEN=.*$/MARKET_GITHUB_TOKEN=$GH_TOKEN/" $ENV_FILE sed -i "s/^MARKETPLACE_INSTALLATION_URL=.*$/MARKETPLACE_INSTALLATION_URL=$MARKETPLACE_INSTALLATION_URL/" $ENV_FILE - - name: Refresh Docker images + - name: Build and bring up containers without cache working-directory: ./marketplace-build run: | - docker compose down - docker compose up -d + docker compose up --build --force-recreate -d diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml index f316d0d91..8eeeb1cfb 100644 --- a/.github/workflows/docker-release.yml +++ b/.github/workflows/docker-release.yml @@ -17,9 +17,11 @@ env: jobs: build: + name: Build Docker images uses: ./.github/workflows/docker-build.yml release: + name: Tag and publish image to GH packages needs: build runs-on: self-hosted permissions: @@ -27,8 +29,26 @@ jobs: contents: read steps: + - name: Wait for containers to be up and running + working-directory: ./marketplace-build + run: | + # Wait for up to 300 seconds for the containers to be up + timeout=300 + start_time=$(date +%s) + while [ $(($(date +%s) - start_time)) -lt $timeout ]; do + if docker compose ps | grep -q "Up"; then + echo "Containers are up and running." + exit 0 + fi + echo "Waiting for containers to start..." + sleep 5 + done + echo "Containers did not start within the timeout period." + exit 1 + - name: Log in to registry run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + - name: Refine release version run: | # This strips the git ref prefix from the version. @@ -36,6 +56,7 @@ jobs: # This uses the Docker `latest` tag convention. [ "$VERSION" == "main" ] && VERSION=latest echo "VERSION=$VERSION" >> $GITHUB_ENV + - name: Release Marketplace UI image run: | UI_IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$UI_IMAGE_NAME diff --git a/marketplace-build/config/nginx/nginx.conf b/marketplace-build/config/nginx/nginx.conf index e9fe9ac0c..e8704aa0a 100644 --- a/marketplace-build/config/nginx/nginx.conf +++ b/marketplace-build/config/nginx/nginx.conf @@ -8,5 +8,9 @@ http { root /usr/share/nginx/html; index index.html; + + location / { + try_files $uri $uri/ /index.html; + } } }