name: CI on: push: branches: - Django workflow_dispatch: concurrency: group: ci-${{ github.ref }} cancel-in-progress: true jobs: docker-ci: if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && contains(github.event.head_commit.message, '[ci]')) runs-on: ubuntu-latest timeout-minutes: 40 env: DJANGO_SECRET_KEY: ${{ secrets.DJANGO_SECRET_KEY }} DJANGO_DEBUG: "False" DJANGO_ALLOWED_HOSTS: "127.0.0.1,localhost" IMAGE_NAME: achievement_inputing_ci ES_IMAGE: docker.elastic.co/elasticsearch/elasticsearch:7.17.9 NET_NAME: ci-net steps: - name: Prepare Docker network run: | docker network inspect "$NET_NAME" >/dev/null 2>&1 || docker network create "$NET_NAME" - name: Start Elasticsearch run: | docker run -d --rm --name es --network "$NET_NAME" -p 9200:9200 \ -e discovery.type=single-node \ -e xpack.security.enabled=false \ -e ES_JAVA_OPTS="-Xms512m -Xmx512m" \ "$ES_IMAGE" - name: Wait for Elasticsearch run: | for i in $(seq 1 60); do if curl -sf http://localhost:9200 >/dev/null; then exit 0; fi sleep 1 done exit 1 - name: Build application image run: | docker build -t "$IMAGE_NAME" -f Dockerfile . - name: Run checks and tests run: | docker run --rm --network "$NET_NAME" \ -e DJANGO_SECRET_KEY="$DJANGO_SECRET_KEY" \ -e DJANGO_DEBUG="$DJANGO_DEBUG" \ -e DJANGO_ALLOWED_HOSTS="$DJANGO_ALLOWED_HOSTS" \ -e ELASTICSEARCH_URL="http://es:9200" \ "$IMAGE_NAME" \ sh -lc "python manage.py migrate --noinput && python manage.py check --deploy && python -m compileall . && python manage.py collectstatic --noinput && python manage.py test" - name: Stop Elasticsearch run: | docker rm -f es || true