Docker Image CI #254
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
| name: Docker Image CI | |
| on: | |
| push: | |
| branches: | |
| - '**' | |
| tags: | |
| - 'v*' | |
| schedule: | |
| - cron: '35 5 * * *' | |
| workflow_dispatch: | |
| env: | |
| HOST_PORT: 8080 | |
| DOCKER_PORT: 80 | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Build the Docker image | |
| run: docker build . --file Dockerfile --tag docker-nginx-webdav:latest | |
| - name: Test the image with no USERNAME/PASSWORD | |
| run: | | |
| docker run --name test0 -d -p$HOST_PORT:$DOCKER_PORT docker-nginx-webdav:latest | |
| docker ps | |
| echo "Test with no credentials" | |
| export RESULT=$(curl -I http://localhost:$HOST_PORT | sed -e"s/\r//" | head -n1) | |
| export EXPECTED="HTTP/1.1 200 OK" | |
| if [ "$RESULT" != "HTTP/1.1 200 OK" ]; then | |
| echo "curl returned $RESULT, but $EXPECTED was expected" | |
| exit 5 | |
| fi | |
| echo "Upload file" | |
| echo "hello anonymous" > testfile | |
| curl -T testfile http://localhost:$HOST_PORT/testfile || exit 7 | |
| echo "Download file" | |
| curl -o testfile2 http://@localhost:$HOST_PORT/testfile || exit 8 | |
| cmp testfile testfile2 || exit 9 | |
| docker kill test0 | |
| - name: Test the image with env USERNAME/PASSWORD | |
| run: | | |
| docker run --name test1 -d -p$HOST_PORT:$DOCKER_PORT -eUSERNAME=user -ePASSWORD=password docker-nginx-webdav:latest | |
| docker ps | |
| echo "Test with correct user / password" | |
| export RESULT=$(curl -I http://user:password@localhost:$HOST_PORT | sed -e"s/\r//" | head -n1) | |
| export EXPECTED="HTTP/1.1 200 OK" | |
| if [ "$RESULT" != "HTTP/1.1 200 OK" ]; then | |
| echo "curl returned $RESULT, but $EXPECTED was expected" | |
| exit 5 | |
| fi | |
| echo "Test with wrong user / password" | |
| export RESULT=$(curl -I http://localhost:$HOST_PORT | sed -e"s/\r//" | head -n1) | |
| export EXPECTED="HTTP/1.1 401 Unauthorized" | |
| if [ "$RESULT" != "HTTP/1.1 401 Unauthorized" ]; then | |
| echo "curl returned $RESULT, but $EXPECTED was expected" | |
| exit 6 | |
| fi | |
| echo "Upload file" | |
| echo "hello world" > testfile | |
| curl -T testfile http://user:password@localhost:$HOST_PORT/testfile || exit 7 | |
| echo "Download file" | |
| curl -o testfile2 http://user:password@localhost:$HOST_PORT/testfile || exit 8 | |
| cmp testfile testfile2 || exit 9 | |
| docker kill test1 | |
| - name: Test the image with file USERNAME/PASSWORD | |
| run: | | |
| echo -n "us3r" > username | |
| echo -n "pAssw0rd" > password | |
| docker run --name test2 -d -p$HOST_PORT:$DOCKER_PORT -v$PWD/username:/username -v$PWD/password:/password -eUSERNAME_FILE=/username -ePASSWORD_FILE=/password docker-nginx-webdav:latest | |
| docker ps | |
| echo "Test with correct user / password" | |
| export RESULT=$(curl -I http://us3r:pAssw0rd@localhost:$HOST_PORT | sed -e"s/\r//" | head -n1) | |
| export EXPECTED="HTTP/1.1 200 OK" | |
| if [ "$RESULT" != "HTTP/1.1 200 OK" ]; then | |
| echo "curl returned $RESULT, but $EXPECTED was expected" | |
| exit 5 | |
| fi | |
| echo "Test with wrong user / password" | |
| export RESULT=$(curl -I http://localhost:$HOST_PORT | sed -e"s/\r//" | head -n1) | |
| export EXPECTED="HTTP/1.1 401 Unauthorized" | |
| if [ "$RESULT" != "HTTP/1.1 401 Unauthorized" ]; then | |
| echo "curl returned $RESULT, but $EXPECTED was expected" | |
| exit 6 | |
| fi | |
| docker kill test2 | |
| - name: Extract metadata (tags, labels) for Docker | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: sfuhrm/docker-nginx-webdav | |
| - name: Build and push Docker image | |
| id: push | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} |