diff --git a/.github/e2e/harbor/env b/.github/e2e/harbor/env new file mode 100644 index 0000000..05ec459 --- /dev/null +++ b/.github/e2e/harbor/env @@ -0,0 +1,8 @@ +REGISTRY_FQDN=localhost:8081 +REGISTRY_USER=admin +REGISTRY_PASSWORD=Harbor12345 +REGISTRY_SLUG=localhost:8081/test-docker-action/test-docker-action + +HARBOR_HOST=localhost +HARBOR_PORT=8081 +HARBOR_PROJECT=test-docker-action diff --git a/.github/e2e/harbor/install.sh b/.github/e2e/harbor/install.sh new file mode 100755 index 0000000..d0a6af2 --- /dev/null +++ b/.github/e2e/harbor/install.sh @@ -0,0 +1,79 @@ +#!/usr/bin/env bash +set -eu + +: "${HARBOR_VERSION:=v2.7.0}" +: "${HARBOR_HOST:=localhost}" +: "${HARBOR_PORT:=49154}" +: "${REGISTRY_USER:=admin}" +: "${REGISTRY_PASSWORD:=Harbor12345}" + +: "${HARBOR_PROJECT:=test-docker-action}" + +project_post_data() { + cat </dev/null + yq --no-colors harbor.yml +) +echo "::endgroup::" + +# install and start +echo "::group::Installing Harbor" +( + cd /tmp/harbor + set -x + ./install.sh + sleep 10 + netstat -aptn +) +echo "::endgroup::" + +# compose config +echo "::group::Compose config" +( + cd /tmp/harbor + set -x + docker compose config +) +echo "::endgroup::" + +# create project +echo "::group::Creating project" +( + set -x + curl --fail -v -k --max-time 10 -u "$REGISTRY_USER:$REGISTRY_PASSWORD" -X POST -H "Content-Type: application/json" -d "$(project_post_data)" "http://$HARBOR_HOST:$HARBOR_PORT/api/v2.0/projects" +) +echo "::endgroup::" + +# list projects +echo "::group::List projects" +( + set -x + curl --fail -s -k --max-time 10 -u "$REGISTRY_USER:$REGISTRY_PASSWORD" -H "Content-Type: application/json" "http://$HARBOR_HOST:$HARBOR_PORT/api/v2.0/projects" | jq +) +echo "::endgroup::" diff --git a/.github/e2e/nexus/docker-compose.yml b/.github/e2e/nexus/docker-compose.yml new file mode 100644 index 0000000..0b5c965 --- /dev/null +++ b/.github/e2e/nexus/docker-compose.yml @@ -0,0 +1,8 @@ +services: + nexus: + image: sonatype/nexus3:${NEXUS_VERSION:-latest} + volumes: + - "./data:/nexus-data" + ports: + - "8081:8081" + - "8082:8082" diff --git a/.github/e2e/nexus/env b/.github/e2e/nexus/env new file mode 100644 index 0000000..798d957 --- /dev/null +++ b/.github/e2e/nexus/env @@ -0,0 +1,9 @@ +REGISTRY_FQDN=localhost:8082 +REGISTRY_USER=admin +REGISTRY_PASSWORD=Nexus12345 +REGISTRY_SLUG=localhost:8082/test-docker-action + +NEXUS_HOST=localhost +NEXUS_PORT=8081 +NEXUS_REGISTRY_PORT=8082 +NEXUS_REPO=test-docker-action diff --git a/.github/e2e/nexus/install.sh b/.github/e2e/nexus/install.sh new file mode 100755 index 0000000..7f4f82d --- /dev/null +++ b/.github/e2e/nexus/install.sh @@ -0,0 +1,93 @@ +#!/usr/bin/env bash +set -eu + +SCRIPT_DIR=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd) + +: "${NEXUS_VERSION:=3.47.1}" +: "${NEXUS_HOST:=localhost}" +: "${NEXUS_PORT:=8081}" +: "${NEXUS_REGISTRY_PORT:=8082}" +: "${REGISTRY_USER:=admin}" +: "${REGISTRY_PASSWORD:=Nexus12345}" + +: "${NEXUS_REPO:=test-docker-action}" + +createrepo_post_data() { + cat <> $GITHUB_ENV + - + name: Set up BuildKit config + run: | + touch /tmp/buildkitd.toml + if [ "${{ matrix.type }}" = "local" ]; then + echo -e "[registry.\"${{ env.REGISTRY_FQDN }}\"]\nhttp = true\ninsecure = true" > /tmp/buildkitd.toml + fi + - + name: Set up Docker daemon + if: matrix.type == 'local' + run: | + if [ ! -e /etc/docker/daemon.json ]; then + echo '{}' | tee /etc/docker/daemon.json >/dev/null + fi + DOCKERD_CONFIG=$(jq '.+{"insecure-registries":["http://${{ env.REGISTRY_FQDN }}"]}' /etc/docker/daemon.json) + sudo tee /etc/docker/daemon.json <<<"$DOCKERD_CONFIG" >/dev/null + sudo service docker restart + - + name: Install ${{ matrix.name }} + if: matrix.type == 'local' + run: | + sudo -E bash ./.github/e2e/${{ matrix.id }}/install.sh - name: Docker meta id: meta uses: docker/metadata-action@v4 with: - images: ${{ matrix.slug }} + images: ${{ env.REGISTRY_SLUG || matrix.slug }} tags: | type=ref,event=branch type=ref,event=tag @@ -100,17 +155,19 @@ jobs: uses: docker/setup-buildx-action@v2 with: version: ${{ inputs.buildx-version || env.BUILDX_VERSION }} - buildkitd-flags: --debug + config: /tmp/buildkitd.toml + buildkitd-flags: --debug --allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host driver-opts: | image=${{ inputs.buildkit-image || env.BUILDKIT_IMAGE }} + network=host - name: Login to Registry if: github.event_name != 'pull_request' uses: docker/login-action@v2 with: - registry: ${{ matrix.registry }} - username: ${{ secrets[matrix.username_secret] }} - password: ${{ secrets[matrix.password_secret] }} + registry: ${{ env.REGISTRY_FQDN || matrix.registry }} + username: ${{ env.REGISTRY_USER || secrets[matrix.username_secret] }} + password: ${{ env.REGISTRY_PASSWORD || secrets[matrix.password_secret] }} - name: Build and push uses: ./ @@ -121,16 +178,14 @@ jobs: push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - cache-from: type=registry,ref=${{ matrix.slug }}:master + cache-from: type=registry,ref=${{ env.REGISTRY_SLUG || matrix.slug }}:master cache-to: type=inline - name: Inspect image - if: github.event_name != 'pull_request' run: | - docker pull ${{ matrix.slug }}:${{ steps.meta.outputs.version }} - docker image inspect ${{ matrix.slug }}:${{ steps.meta.outputs.version }} + docker pull ${{ env.REGISTRY_SLUG || matrix.slug }}:${{ steps.meta.outputs.version }} + docker image inspect ${{ env.REGISTRY_SLUG || matrix.slug }}:${{ steps.meta.outputs.version }} - name: Check manifest - if: github.event_name != 'pull_request' run: | - docker buildx imagetools inspect ${{ matrix.slug }}:${{ steps.meta.outputs.version }} --format '{{json .}}' + docker buildx imagetools inspect ${{ env.REGISTRY_SLUG || matrix.slug }}:${{ steps.meta.outputs.version }} --format '{{json .}}'