diff --git a/.github/workflows/smoke-test.yml b/.github/workflows/smoke-test.yml index 561a53a..88a6b5e 100644 --- a/.github/workflows/smoke-test.yml +++ b/.github/workflows/smoke-test.yml @@ -17,32 +17,35 @@ jobs: build-and-smoke: runs-on: ubuntu-latest timeout-minutes: 30 + services: + registry: + image: registry:3 + ports: ["5000:5000"] steps: - uses: actions/checkout@v6.0.2 with: - ref: 'master' + ref: ${{ github.sha }} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v4.1.0 + with: + driver-opts: network=host - name: Resolve build args id: args run: | - echo "url=${{ github.event.inputs.netdisco_git_url || 'https://github.com/netdisco/netdisco.git' }}" >> "$GITHUB_OUTPUT" - echo "committish=${{ github.event.inputs.committish || 'HEAD' }}" >> "$GITHUB_OUTPUT" + echo "URL=${{ github.event.inputs.netdisco_git_url || 'https://github.com/netdisco/netdisco.git' }}" >> "$GITHUB_OUTPUT" + echo "COMMITTISH=${{ github.event.inputs.committish || 'HEAD' }}" >> "$GITHUB_OUTPUT" - name: Build images with Bake and Cache uses: docker/bake-action@v7.2.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + COMMITTISH: ${{ steps.args.outputs.committish }} with: - files: compose.build.yaml - targets: | - netdisco-postgresql - netdisco-backend - netdisco-web - push: false - load: true + files: docker-bake.hcl + targets: standalone + push: true set: | *.cache-from=type=gha *.cache-to=type=gha,mode=max @@ -56,11 +59,11 @@ jobs: # netdisco user range — same failure mode as OpenShift restricted-v2 # SCC. local::lib must be able to bootstrap (i.e. /home/netdisco # has to be writable for supplemental gid 0). - for tag in latest-backend latest-web; do - echo "::group::arbitrary UID test: netdisco/netdisco:$tag" + for tag in ${{ steps.args.outputs.committish }}-backend ${{ steps.args.outputs.committish }}-web; do + echo "::group::arbitrary UID test: localhost:5000/netdisco:$tag" docker run --rm --user 1000050000 \ --entrypoint /home/netdisco/bin/localenv \ - "netdisco/netdisco:$tag" \ + "localhost:5000/netdisco:$tag" \ perl -e 'print "ok\n"' echo "::endgroup::" done @@ -71,13 +74,15 @@ jobs: sudo chown -R 901:901 netdisco - name: Start the stack - run: docker compose up --detach + env: + COMMITTISH: ${{ steps.args.outputs.committish }} + run: docker compose -f compose.yaml -f compose.mixin.webport.yaml -f compose.mixin.localregistry.yaml --verbose up --detach - name: Wait for netdisco-web to respond run: | set -e for i in $(seq 1 90); do - code=$(curl -s -o /dev/null -w '%{http_code}' http://localhost:5000/ || true) + code=$(curl -s -o /dev/null -w '%{http_code}' http://localhost:3000/ || true) echo "[$i] HTTP $code" if [ -n "$code" ] && [ "$code" -lt 500 ] && [ "$code" -ne 000 ]; then echo "netdisco-web responded with $code after ${i}s" diff --git a/README.md b/README.md index 643aa75..fb2336c 100644 --- a/README.md +++ b/README.md @@ -98,9 +98,22 @@ A `/health` endpoint (suitable for container/load-balancer health probes) is ava ## Rebuilding -If you wish to build the images locally, use [this compose file](https://raw.githubusercontent.com/netdisco/netdisco-docker/refs/heads/master/compose.build.yaml) (it's not a mix-in): +If you wish to build the images locally, use a modern version of Docker which will include Docker Bake. - docker compose -f compose.build.yaml build --no-cache + COMMITTISH=HEAD docker buildx bake + +Replace `HEAD` with the Git reference you wish to build from the [Netdisco repository](https://github.com/netdisco/netdisco); the +name of a branch works well. You can also add `NETDISCO_GIT_URL` to point to any other online repo, or a local folder. + +This default target rebuilds only "netdisco-backend" and "netdisco-web". You can use the `standalone` target to rebuild with "netdisco-postgresql", +or the `all` target to rebuild with both "netdisco-postgresql" and "netdisco-postgresql-13". + +The build images will NOT be tagged with "netdisco" prefix (they will look like "localhost:5000/netdisco:latest-web" in `docker images --tree`). To use them +with our Docker Compose files (as above), we have a [mix-in file](https://raw.githubusercontent.com/netdisco/netdisco-docker/refs/heads/master/compose.mixin.localregistry.yaml): + + COMMITTISH=HEAD docker compose -f compose.yaml -f compose.mixin.localregistry.yaml up + +Specifying the `COMMITTISH` will ensure you run the same images you just built (in case there are others in your Docker). ## Kubernetes / OpenShift diff --git a/compose.build.yaml b/compose.build.yaml deleted file mode 100644 index 989c453..0000000 --- a/compose.build.yaml +++ /dev/null @@ -1,44 +0,0 @@ -services: - -# https://docs.docker.com/compose/how-tos/dependent-images/#use-another-services-image-as-the-base-image - - netdisco-postgresql: - build: - context: ./netdisco-postgresql - tags: - - netdisco/netdisco:latest-postgresql - - localhost:5000/netdisco:latest-postgresql - - netdisco-postgresql-13: - build: - context: ./netdisco-postgresql - args: - PGVER: 13.4 - tags: - - netdisco/netdisco:latest-postgresql-13 - - localhost:5000/netdisco:latest-postgresql-13 - - netdisco-base: - build: - context: ./netdisco-base - tags: - - netdisco/netdisco:latest-base - - localhost:5000/netdisco:latest-base - - netdisco-backend: - build: - context: ./netdisco-backend - tags: - - netdisco/netdisco:latest-backend - - localhost:5000/netdisco:latest-backend - additional_contexts: - "localhost:5000/netdisco:latest-base": "service:netdisco-base" - - netdisco-web: - build: - context: ./netdisco-web - tags: - - netdisco/netdisco:latest-web - - localhost:5000/netdisco:latest-web - additional_contexts: - "localhost:5000/netdisco:latest-base": "service:netdisco-base" diff --git a/compose.mixin.localregistry.yaml b/compose.mixin.localregistry.yaml new file mode 100644 index 0000000..68e5a4b --- /dev/null +++ b/compose.mixin.localregistry.yaml @@ -0,0 +1,16 @@ +services: + + netdisco-postgresql: + image: localhost:5000/netdisco:${COMMITTISH:-latest}-postgresql + + netdisco-postgresql-13: + image: localhost:5000/netdisco:${COMMITTISH:-latest}-postgresql-13 + + netdisco-db-init: + image: localhost:5000/netdisco:${COMMITTISH:-latest}-backend + + netdisco-backend: + image: localhost:5000/netdisco:${COMMITTISH:-latest}-backend + + netdisco-web: + image: localhost:5000/netdisco:${COMMITTISH:-latest}-web diff --git a/compose.mixin.webport.yaml b/compose.mixin.webport.yaml new file mode 100644 index 0000000..b737ced --- /dev/null +++ b/compose.mixin.webport.yaml @@ -0,0 +1,5 @@ +services: + + netdisco-web: + ports: !override + - "127.0.0.1:3000:5000" diff --git a/docker-bake.hcl b/docker-bake.hcl new file mode 100644 index 0000000..4bee308 --- /dev/null +++ b/docker-bake.hcl @@ -0,0 +1,94 @@ +variable "NETDISCO_GIT_URL" { + default = "https://github.com/netdisco/netdisco.git" +} + +variable "COMMITTISH" { + default = "latest" +} + +variable "BUILD_DATE" { + default = "" +} + +group "default" { + targets = ["netdisco-backend","netdisco-web"] +} + +group "standalone" { + targets = ["netdisco-postgresql","netdisco-backend", "netdisco-web"] +} + +group "all" { + targets = ["netdisco-postgresql","netdisco-postgresql-13","netdisco-backend", "netdisco-web"] +} + +target "netdisco-base" { + context = "./netdisco-base" + dockerfile = "Dockerfile" + tags = [ + "localhost:5000/netdisco:${COMMITTISH}-base", + ] + args = { + COMMITTISH = COMMITTISH + NETDISCO_GIT_URL = NETDISCO_GIT_URL + BUILD_DATE = BUILD_DATE + } + output = ["type=docker"] +} + +target "netdisco-web" { + context = "./netdisco-web" + dockerfile = "Dockerfile" + tags = [ + "localhost:5000/netdisco:${COMMITTISH}-web", + ] + args = { + COMMITTISH = COMMITTISH + } + contexts = { + "localhost:5000/netdisco:${COMMITTISH}-base" = "target:netdisco-base" + } + output = ["type=docker"] +} + +target "netdisco-backend" { + context = "./netdisco-backend" + dockerfile = "Dockerfile" + tags = [ + "localhost:5000/netdisco:${COMMITTISH}-backend", + ] + args = { + COMMITTISH = COMMITTISH + } + contexts = { + "localhost:5000/netdisco:${COMMITTISH}-base" = "target:netdisco-base" + } + output = ["type=docker"] +} + +target "netdisco-postgresql" { + context = "./netdisco-postgresql" + dockerfile = "Dockerfile" + tags = [ + "localhost:5000/netdisco:${COMMITTISH}-postgresql", + ] + args = { + COMMITTISH = COMMITTISH + BUILD_DATE = BUILD_DATE + } + output = ["type=docker"] +} + +target "netdisco-postgresql-13" { + context = "./netdisco-postgresql" + dockerfile = "Dockerfile" + tags = [ + "localhost:5000/netdisco:${COMMITTISH}-postgresql-13", + ] + args = { + PGVER = "13.4" + COMMITTISH = COMMITTISH + BUILD_DATE = BUILD_DATE + } + output = ["type=docker"] +} diff --git a/netdisco-backend/Dockerfile b/netdisco-backend/Dockerfile index 1b5af3a..a03224f 100644 --- a/netdisco-backend/Dockerfile +++ b/netdisco-backend/Dockerfile @@ -1,6 +1,6 @@ # vim: ft=Dockerfile -ARG TAG=latest -FROM localhost:5000/netdisco:${TAG}-base +ARG COMMITTISH=latest +FROM localhost:5000/netdisco:${COMMITTISH}-base USER root diff --git a/netdisco-web/Dockerfile b/netdisco-web/Dockerfile index 6e3908c..8d2c50d 100644 --- a/netdisco-web/Dockerfile +++ b/netdisco-web/Dockerfile @@ -1,6 +1,6 @@ # vim: ft=Dockerfile -ARG TAG=latest -FROM localhost:5000/netdisco:${TAG}-base +ARG COMMITTISH=latest +FROM localhost:5000/netdisco:${COMMITTISH}-base LABEL org.label-schema.name="netdisco-web" \ org.label-schema.description="Web Frontend for Netdisco"