diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index f73283917..5185bac1e 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' @@ -39,8 +53,7 @@ jobs: sed -i "s/^MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET=.*$/MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET=$MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET/" $ENV_FILE sed -i "s/^MARKET_JWT_SECRET_KEY=.*$/MARKET_JWT_SECRET_KEY=$MARKET_JWT_SECRET_KEY/" $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