[Docker] Fix networking and startup issues with Docker Compose scripts. Update scripts to align with best practices #8953
Workflow file for this run
This file contains hidden or 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
| # DSpace Docker image build for hub.docker.com | |
| name: Docker images | |
| # Run this Build for all pushes to 'main' or maintenance branches, or tagged releases. | |
| # Also run for PRs to ensure PR doesn't break Docker build process | |
| # NOTE: uses "reusable-docker-build.yml" in DSpace/DSpace to actually build each of the Docker images | |
| # https://github.com/DSpace/DSpace/blob/main/.github/workflows/reusable-docker-build.yml | |
| # | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - 'dspace-**' | |
| tags: | |
| - 'dspace-**' | |
| pull_request: | |
| permissions: | |
| contents: read # to fetch code (actions/checkout) | |
| packages: write # to write images to GitHub Container Registry (GHCR) | |
| jobs: | |
| ############################################################# | |
| # Build/Push the 'dspace/dspace-angular' image | |
| ############################################################# | |
| dspace-angular: | |
| # Ensure this job never runs on forked repos. It's only executed for 'dspace/dspace-angular' | |
| if: github.repository == 'dspace/dspace-angular' | |
| # Use the reusable-docker-build.yml script from DSpace/DSpace repo to build our Docker image | |
| uses: DSpace/DSpace/.github/workflows/reusable-docker-build.yml@main | |
| with: | |
| build_id: dspace-angular-dev | |
| image_name: dspace/dspace-angular | |
| dockerfile_path: ./Dockerfile | |
| secrets: | |
| DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
| DOCKER_ACCESS_TOKEN: ${{ secrets.DOCKER_ACCESS_TOKEN }} | |
| ############################################################# | |
| # Build/Push the 'dspace/dspace-angular' image ('-dist' tag) | |
| ############################################################# | |
| dspace-angular-dist: | |
| # Ensure this job never runs on forked repos. It's only executed for 'dspace/dspace-angular' | |
| if: github.repository == 'dspace/dspace-angular' | |
| # Use the reusable-docker-build.yml script from DSpace/DSpace repo to build our Docker image | |
| uses: DSpace/DSpace/.github/workflows/reusable-docker-build.yml@main | |
| with: | |
| build_id: dspace-angular-dist | |
| image_name: dspace/dspace-angular | |
| dockerfile_path: ./Dockerfile.dist | |
| # As this is a "dist" image, its tags are all suffixed with "-dist". Otherwise, it uses the same | |
| # tagging logic as the primary 'dspace/dspace-angular' image above. | |
| tags_flavor: suffix=-dist | |
| secrets: | |
| DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
| DOCKER_ACCESS_TOKEN: ${{ secrets.DOCKER_ACCESS_TOKEN }} | |
| # Enable redeploy of sandbox & demo if the branch for this image matches the deployment branch of | |
| # these sites as specified in reusable-docker-build.xml | |
| REDEPLOY_SANDBOX_URL: ${{ secrets.REDEPLOY_SANDBOX_URL }} | |
| REDEPLOY_DEMO_URL: ${{ secrets.REDEPLOY_DEMO_URL }} | |
| ################################################################################# | |
| # Test Deployment via Docker to ensure newly built images are working properly | |
| ################################################################################# | |
| docker-deploy: | |
| # Ensure this job never runs on forked repos. It's only executed for 'dspace/dspace-angular' | |
| if: github.repository == 'dspace/dspace-angular' | |
| runs-on: ubuntu-latest | |
| # Must run after all major images are built | |
| needs: [dspace-angular, dspace-angular-dist] | |
| env: | |
| # Override default dspace.server.url & REST 'host' because backend starts at http://127.0.0.1:8080 | |
| dspace__P__server__P__url: http://127.0.0.1:8080/server | |
| DSPACE_REST_HOST: 127.0.0.1 | |
| # Override default dspace.ui.url to also use 127.0.0.1. | |
| dspace__P__ui__P__url: http://127.0.0.1:4000 | |
| # Docker Registry to use for Docker compose scripts below. | |
| # If this is a PR, then we need to use docker.io (as the registry must be public), | |
| # Otherwise we default to ghcr.io to avoid aggressive rate limits at DockerHub. | |
| DOCKER_REGISTRY: ${{ github.event_name == 'pull_request' && 'docker.io' || 'ghcr.io' }} | |
| steps: | |
| # Checkout our codebase (to get access to Docker Compose scripts) | |
| - name: Checkout codebase | |
| uses: actions/checkout@v4 | |
| # Download Docker image artifacts (which were just built by reusable-docker-build.yml) | |
| - name: Download Docker image artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| # Download all amd64 Docker images (TAR files) into the /tmp/docker directory | |
| pattern: docker-image-*-linux-amd64 | |
| path: /tmp/docker | |
| merge-multiple: true | |
| # Load each of the images into Docker by calling "docker image load" for each. | |
| # This ensures we are using the images just built & not any prior versions on DockerHub | |
| - name: Load all downloaded Docker images | |
| run: | | |
| find /tmp/docker -type f -name "*.tar" -exec docker image load --input "{}" \; | |
| docker image ls -a | |
| # Start backend using our compose script in the codebase. | |
| - name: Start production frontend and backend in Docker | |
| run: | | |
| docker compose -f docker/docker-compose-dist.yml -f docker/docker-compose-rest.yml up -d | |
| sleep 10 | |
| docker container ls | |
| # Create a test admin account. Load test data from a simple set of AIPs as defined in cli.ingest.yml | |
| - name: Load test data into Backend | |
| run: | | |
| docker compose -f docker/cli.yml run --rm dspace-cli create-administrator -e [email protected] -f admin -l user -p admin -c en | |
| docker compose -f docker/cli.yml -f docker/cli.ingest.yml run --rm dspace-cli | |
| # Verify backend started successfully. | |
| # 1. Make sure root endpoint is responding (check for dspace.name defined in docker-compose.yml) | |
| # 2. Also check /collections endpoint to ensure the test data loaded properly (check for a collection name in AIPs) | |
| - name: Verify backend is responding properly | |
| run: | | |
| result=$(wget -O- -q http://127.0.0.1:8080/server/api) | |
| echo "$result" | |
| echo "$result" | grep -oE "\"DSpace Started with Docker Compose\"" | |
| result=$(wget -O- -q http://127.0.0.1:8080/server/api/core/collections) | |
| echo "$result" | |
| echo "$result" | grep -oE "\"Dog in Yard\"" | |
| # Verify production frontend started successfully. | |
| # 1. Make sure /home path has "DSpace software" (this is in the footer of the page) | |
| # 2. Also check /community-list page lists one of the test Communities in the loaded test data | |
| - name: Verify frontend is responding properly | |
| run: | | |
| result=$(wget -O- -q http://127.0.0.1:4000/home) | |
| echo "$result" | |
| echo "$result" | grep -oE "\"DSpace software\"" | |
| result=$(wget -O- -q http://127.0.0.1:4000/community-list) | |
| echo "$result" | |
| echo "$result" | grep -oE "\"Dog Photos Community\"" | |
| # Shutdown our containers | |
| - name: Shutdown Docker containers | |
| run: | | |
| docker compose -f docker/docker-compose-dist.yml -f docker/docker-compose-rest.yml down |