v1.0.0: ci: add test

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2024-03-14 18:36:45 +01:00
commit 024a9feda2
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
3 changed files with 64 additions and 1 deletions

View file

@ -1,5 +1,6 @@
variables:
IMAGE_VERSION: $CI_COMMIT_SHORT_SHA
IMAGE_TYPE: users
default:
image: debian:11
@ -33,4 +34,24 @@ build:
DOCKER_PATH: '.'
script:
- docker build --pull -t $CI_REGISTRY_IMAGE:$IMAGE_VERSION-release --target release $DOCKER_PATH
- docker save $CI_REGISTRY_IMAGE:$IMAGE_VERSION-release | gzip > $IMAGE_TYPE-$IMAGE_VERSION-release.tar.gz
- docker save $CI_REGISTRY_IMAGE:$IMAGE_VERSION-release | gzip > $IMAGE_TYPE-$IMAGE_VERSION-release.tar.gz
integration_test:
stage: test
image: golang:1.21-alpine
variables:
DOCKER_TLS_VERIFY: 1
DOCKER_CERT_PATH: /certs/client
DOCKER_HOST: tcp://docker:2376/
DOCKER_URL: docker
before_script:
- apk update && apk add --no-cache docker-cli
- apk add bash
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker login -u gnomezworc -p $DOCKERHUB_TOKEN
script:
- bash -ex ./scripts/prepar_test.sh
- . ./config/test.src
- go test -v ./cmd/
needs:
- build

0
config/test.src Normal file
View file

42
scripts/prepar_test.sh Normal file
View file

@ -0,0 +1,42 @@
#!/bin/bash
cat <<ENDFILE >> /etc/apk/repositories
http://ftp.halifax.rwth-aachen.de/alpine/v3.16/main
http://ftp.halifax.rwth-aachen.de/alpine/v3.16/community
ENDFILE
apk update
apk add docker docker-cli-compose
docker version
docker compose version
docker load --input "$IMAGE_TYPE-$IMAGE_VERSION-release.tar.gz"
docker tag $CI_REGISTRY_IMAGE:$IMAGE_VERSION-release $IMAGE_TYPE:latest
cat <<ENDFILE > docker-compose.yml
version: '3.1'
services:
postgres:
image: postgres:15.2-alpine3.17
restart: unless-stopped
environment:
POSTGRES_USER: 'acc'
POSTGRES_PASSWORD: 'totor'
POSTGRES_DB: 'accounts'
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
interval: 10s
timeout: 5s
retries: 5
users:
image: $IMAGE_TYPE
volumes:
- ./docker/keys:/keys
depends_on:
postgres:
condition: service_healthy
ENDFILE
docker compose pull --quiet --ignore-pull-failures
docker images
docker compose up -d