Add e2e tests (#471)

Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2021-08-21 14:09:06 +02:00
committed by GitHub
parent 48a4ed2f69
commit ac2e41de80
13 changed files with 257 additions and 3 deletions

View File

@@ -1,8 +1,10 @@
/.dev
/.idea
/*.iml
.dev
/.github
/bin
/dist
/site
/coverage.txt
/test

View File

@@ -39,6 +39,10 @@ jobs:
uses: docker/bake-action@v1
with:
targets: validate
pull: true
set: |
*.cache-from=type=gha,scope=diun-validate
*.cache-to=type=gha,scope=diun-validate,mode=max
test:
runs-on: ubuntu-latest
@@ -56,6 +60,10 @@ jobs:
uses: docker/bake-action@v1
with:
targets: test
pull: true
set: |
*.cache-from=type=gha,scope=diun-test
*.cache-to=type=gha,scope=diun-test,mode=max
-
name: Upload coverage
uses: codecov/codecov-action@v2
@@ -117,6 +125,10 @@ jobs:
uses: docker/bake-action@v1
with:
targets: artifact-all
pull: true
set: |
*.cache-from=type=gha,scope=diun-artifact
*.cache-to=type=gha,scope=diun-artifact,mode=max
-
name: Move artifacts
run: |
@@ -136,7 +148,12 @@ jobs:
./docker-bake.hcl
${{ steps.meta.outputs.bake-file }}
targets: image-all
pull: true
push: ${{ github.event_name != 'pull_request' }}
set: |
*.cache-from=type=gha,scope=diun-artifact
*.cache-from=type=gha,scope=diun-image
*.cache-to=type=gha,scope=diun-image,mode=max
-
name: GitHub Release
uses: softprops/action-gh-release@v1

View File

@@ -36,6 +36,7 @@ jobs:
uses: docker/bake-action@v1
with:
targets: docs
pull: true
-
name: Check GitHub Pages status
uses: crazy-max/ghaction-github-status@v2

107
.github/workflows/e2e.yml vendored Normal file
View File

@@ -0,0 +1,107 @@
name: e2e
on:
push:
branches:
- 'master'
- 'v*'
paths-ignore:
- '**.md'
pull_request:
branches:
- 'master'
- 'v*'
paths-ignore:
- '**.md'
env:
BUILD_TAG: 'crazymax/diun:local'
CONTAINER_NAME: 'diun'
RUNNING_TIMEOUT: '240'
RUNNING_LOG_CHECK: 'Next run in'
jobs:
e2e:
runs-on: ubuntu-latest
services:
redis:
image: redis:6.2.3-alpine
cloudflared:
image: crazymax/cloudflared:latest
options: >-
--label "diun.enable=true"
--label "diun.watch_repo=true"
strategy:
fail-fast: false
matrix:
include:
- folder: docker1
loglevel: debug
- folder: docker2
loglevel: info
- folder: docker3
loglevel: info
- folder: dockerfile1
loglevel: debug
steps:
-
name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Build
uses: docker/bake-action@v1
with:
targets: image-local
pull: true
set: |
*.cache-from=type=gha,scope=diun-image
*.cache-from=type=gha,scope=diun-e2e-${{ matrix.folder }}
*.cache-to=type=gha,scope=diun-e2e-${{ matrix.folder }},mode=max
-
name: Start container
run: |
volFlags="-v $(pwd)/test/${{ matrix.folder }}/diun.yml:/diun.yml:ro"
volFlags="-v /var/run/docker.sock:/var/run/docker.sock ${volFlags}"
if [ -d "$(pwd)/test/${{ matrix.folder }}/mount" ]; then
volFlags="-v $(pwd)/test/${{ matrix.folder }}/mount:/mount ${volFlags}"
fi
docker run -d --name ${{ env.CONTAINER_NAME }} ${volFlags} \
-e "TZ=Europe/Paris" \
-e "LOG_LEVEL=${{ matrix.loglevel }}" \
${{ env.BUILD_TAG }}
-
name: Test run
run: |
TIMEOUT=$((SECONDS + ${{ env.RUNNING_TIMEOUT }}))
while read LOGLINE; do
echo ${LOGLINE}
if [[ ${LOGLINE} == *"${{ env.RUNNING_LOG_CHECK }}"* ]]; then
echo "🎉 Container up!"
break
fi
if [[ $SECONDS -gt ${TIMEOUT} ]]; then
>&2 echo "❌ Failed to run ${{ env.CONTAINER_NAME }} container"
exit 1
fi
done < <(docker logs -f ${{ env.CONTAINER_NAME }} 2>&1)
CONTAINER_STATUS=$(docker container inspect --format "{{.State.Status}}" ${{ env.CONTAINER_NAME }})
if [[ ${CONTAINER_STATUS} != "running" ]]; then
>&2 echo "❌ Container ${{ env.CONTAINER_NAME }} returned status '$CONTAINER_STATUS'"
exit 1
fi
-
name: List images in db
run: |
docker exec -t ${{ env.CONTAINER_NAME }} diun image list
-
name: Container logs
if: always()
run: |
docker logs ${{ env.CONTAINER_NAME }}
docker rm -f ${{ env.CONTAINER_NAME }} > /dev/null 2>&1 || true

View File

@@ -33,8 +33,8 @@ COPY --from=generate /out /
FROM generate AS validate
RUN --mount=type=bind,target=.,rw \
git add -A && cp -rf /out/* .; \
if [ -n "$(git status --porcelain)" ]; then \
if [ -n "$(git status --porcelain -- pb)" ]; then \
echo >&2 'ERROR: Generate result differs. Please update with "docker buildx bake gen-update"'; \
git status --porcelain; \
git status --porcelain -- pb; \
exit 1; \
fi

6
test/docker1/diun.yml Normal file
View File

@@ -0,0 +1,6 @@
watch:
workers: 20
schedule: "0 */6 * * *"
providers:
docker: {}

7
test/docker2/diun.yml Normal file
View File

@@ -0,0 +1,7 @@
watch:
workers: 20
schedule: "0 */6 * * *"
providers:
docker:
watchByDefault: true

8
test/docker3/diun.yml Normal file
View File

@@ -0,0 +1,8 @@
watch:
workers: 20
schedule: "0 */6 * * *"
providers:
docker:
watchByDefault: true
watchStopped: true

15
test/dockerfile1/diun.yml Normal file
View File

@@ -0,0 +1,15 @@
watch:
workers: 20
schedule: "0 */6 * * *"
firstCheckNotif: true
notif:
script:
cmd: "sh"
args:
- "/mount/notif.sh"
providers:
dockerfile:
patterns:
- /mount/Dockerfile*

View File

@@ -0,0 +1,16 @@
# syntax=docker/dockerfile:1.2
# diun.platform=linux/amd64
FROM alpine:latest
# diun.watch_repo=true
# diun.max_tags=10
# diun.platform=linux/amd64
COPY --from=crazymax/yasu / /
# diun.watch_repo=true
# diun.include_tags=^\d+\.\d+\.\d+$
# diun.platform=linux/amd64
RUN --mount=type=bind,target=.,rw \
--mount=type=bind,from=docker/buildx-bin:0.6.0,source=/buildx,target=/usr/bin/buildx \
yasu --version

View File

@@ -0,0 +1,49 @@
# syntax=docker/dockerfile:1.2
ARG GO_VERSION=1.16
# diun.watch_repo=true
# diun.max_tags=100
FROM --platform=$BUILDPLATFORM crazymax/goreleaser-xx:latest AS goreleaser-xx
# diun:"watch_repo=true,max_tags=100"
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS base
COPY --from=goreleaser-xx / /
COPY --from=crazymax/goreleaser-xx:0.162.0 / /
RUN apk add --no-cache ca-certificates gcc file git linux-headers musl-dev tar
WORKDIR /src
FROM base AS build
ARG TARGETPLATFORM
ARG GIT_REF
RUN --mount=type=bind,target=/src,rw \
--mount=type=cache,target=/root/.cache/go-build \
--mount=target=/go/pkg/mod,type=cache \
goreleaser-xx --debug \
--name "diun" \
--dist "/out" \
--hooks="go mod tidy" \
--hooks="go mod download" \
--main="./cmd/main.go" \
--ldflags="-s -w -X 'main.version={{.Version}}'" \
--files="CHANGELOG.md" \
--files="LICENSE" \
--files="README.md"
FROM scratch AS artifacts
COPY --from=build /out/*.tar.gz /
COPY --from=build /out/*.zip /
FROM alpine
LABEL maintainer="CrazyMax"
RUN apk --update --no-cache add \
ca-certificates \
libressl \
&& rm -rf /tmp/* /var/cache/apk/*
COPY --from=build /usr/local/bin/diun /usr/local/bin/diun
RUN diun --version
ENV DIUN_DB_PATH="/data/diun.db"
VOLUME [ "/data" ]
ENTRYPOINT [ "diun" ]

View File

@@ -0,0 +1,25 @@
# syntax=docker/dockerfile:1.2
ARG NODE_VERSION
# foo
# diun:"watch_repo=true,max_tags=100"
FROM node:${NODE_VERSION}-alpine AS base
RUN apk add --no-cache git
WORKDIR /src
FROM base AS deps
RUN --mount=type=bind,target=.,rw \
--mount=type=cache,target=/src/node_modules \
yarn install
FROM deps AS test
ENV RUNNER_TEMP=/tmp/github_runner
ENV RUNNER_TOOL_CACHE=/tmp/github_tool_cache
RUN --mount=type=bind,target=.,rw \
--mount=type=cache,target=/src/node_modules \
--mount=type=bind,from=crazymax/docker,source=/usr/libexec/docker/cli-plugins/docker-buildx,target=/usr/libexec/docker/cli-plugins/docker-buildx \
--mount=type=bind,from=crazymax/docker,source=/usr/local/bin/docker,target=/usr/bin/docker \
yarn run test --coverageDirectory=/tmp/coverage
FROM scratch AS test-coverage
COPY --from=test /tmp/coverage /

View File

@@ -0,0 +1 @@
env|sort