Skip to content

Commit

Permalink
Add auth tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Y0sh1dk committed Dec 17, 2023
1 parent 07b7a39 commit cf4777e
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 2 deletions.
70 changes: 68 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
name: gha-docker-image-exists Test
on:
workflow_dispatch:

env:
REGISTRY_PORT: 5000
REGISTRY_USERNAME: "test-registry-username"
REGISTRY_PASSWORD: "test-registry-password"

jobs:
success:
success-no-auth:
runs-on: ubuntu-latest
steps:
- name: GHA Docker Image Exists
Expand All @@ -18,7 +24,7 @@ jobs:
else
exit 1
fi
fail:
fail-no-auth:
runs-on: ubuntu-latest
steps:
- name: GHA Docker Image Exists
Expand All @@ -34,3 +40,63 @@ jobs:
else
exit 1
fi
success-auth:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Install Task
uses: arduino/setup-task@v1

- name: Setup local registry
run: |
task local-registry-up
- name: GHA Docker Image Exists
id: gha-docker-image-exists
continue-on-error: true
uses: Y0sh1dk/gha-docker-image-exists@main
with:
image: nginx:latest
username: ${{ env.REGISTRY_USERNAME }}
password: ${{ env.REGISTRY_PASSWORD }}
serverAddress: localhost:${{ env.REGISTRY_PORT }}

- name: Check output
run: |
if [ ${{ steps.gha-docker-image-exists.outcome == 'success' }} ]; then
exit 0
else
exit 1
fi
fail-auth:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Install Task
uses: arduino/setup-task@v1

- name: Setup local registry
run: |
task local-registry-up
- name: GHA Docker Image Exists
id: gha-docker-image-exists
continue-on-error: true
uses: Y0sh1dk/gha-docker-image-exists@main
with:
image: nginx:invalid-tag
username: ${{ env.REGISTRY_USERNAME }}
password: ${{ env.REGISTRY_PASSWORD }}
serverAddress: localhost:${{ env.REGISTRY_PORT }}

- name: Check output
run: |
if [ ${{ steps.gha-docker-image-exists.outcome == 'failure' }} ]; then
exit 0
else
exit 1
fi
20 changes: 20 additions & 0 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,26 @@ tasks:
golangci/golangci-lint:{{ .GOLANG_CI_LINT_VERSION }} \
golangci-lint run -v
local-registry-up:
desc: Start local registry
env:
REGISTRY_PORT: "{{ .REGISTRY_PORT | default 5000 }}"
REGISTRY_USERNAME: '{{ .REGISTRY_USERNAME | default "admin" }}'
REGISTRY_PASSWORD: '{{ .REGISTRY_PASSWORD | default "password" }}'
cmds:
- |
docker-compose -f test/docker-compose.yml up -d
local-registry-down:
desc: Step local registry
env:
REGISTRY_PORT: "{{ .REGISTRY_PORT | default 5000 }}"
REGISTRY_USERNAME: "{{ .REGISTRY_USERNAME | default admin }}"
REGISTRY_PASSWORD: "{{ .REGISTRY_PASSWORD | default password }}"
cmds:
- |
docker-compose -f test/docker-compose.yml down -v
default:
silent: true
cmds:
Expand Down
25 changes: 25 additions & 0 deletions test/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: "3"

services:
registry:
image: registry:2
ports:
- "${REGISTRY_PORT?}:5000"
environment:
REGISTRY_AUTH: htpasswd
REGISTRY_AUTH_HTPASSWD_PATH: /httpasswd_storage/htpasswd
REGISTRY_AUTH_HTPASSWD_REALM: Registry Realm
volumes:
- auth-volume:/httpasswd_storage
depends_on:
htpasswd-generator:
condition: service_completed_successfully

htpasswd-generator:
image: httpd:2.4-alpine
command: sh -c "htpasswd -Bbn ${REGISTRY_USERNAME?} ${REGISTRY_PASSWORD?} > /httpasswd_storage/htpasswd && cat /httpasswd_storage/htpasswd"
volumes:
- auth-volume:/httpasswd_storage

volumes:
auth-volume:

0 comments on commit cf4777e

Please sign in to comment.