merge samplelog with nut #187
Workflow file for this run
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: Create and publish a package | |
| on: | |
| push: | |
| branches: | |
| - "main" | |
| - "ar52" | |
| env: | |
| IMAGE_NAME: nes-lter-api-2 | |
| jobs: | |
| # NES-LTER API 2 Automated Testing and Tagging | |
| setup-build-publish: | |
| name: NES-LTER API 2 Setup, Build, and Publish | |
| permissions: | |
| contents: read | |
| packages: write | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Running Automated tests | |
| run: | | |
| # Build and run development version | |
| mv dotenv.template .env | |
| sed -i 's|^VAST_DATA_DIR=.*|VAST_DATA_DIR=./tests|' .env | |
| sed -i 's|^USE_DICTSTORE=FALSE$|USE_DICTSTORE=TRUE|' .env | |
| docker compose -f docker-compose-testing.yml build | |
| docker compose -f docker-compose-testing.yml up --detach | |
| sleep 30 | |
| # Run migrations | |
| docker compose -f docker-compose-testing.yml exec -T api python manage.py migrate --noinput | |
| sh -c "until curl -Is http://localhost:8000; do echo 'waiting for http://localhost:8000'; sleep 10; done" | |
| echo "localhost:8000 running" | |
| # Create admin user and capture token | |
| docker compose -f docker-compose-testing.yml exec -T api \ | |
| python manage.py shell -c "from django.contrib.auth import get_user_model;from rest_framework.authtoken.models import Token;from pathlib import Path;User = get_user_model();u, _ = User.objects.get_or_create(username='admin');u.set_password('admin');u.is_superuser = u.is_staff = True;u.save();token, _ = Token.objects.get_or_create(user=u);Path('/data/token.txt').write_text(token.key); print(token.key)" | |
| # Import the test cruise and CTD data | |
| docker compose -f docker-compose-testing.yml exec -T api python manage.py importall --cruise_name ar77 | |
| docker compose -f docker-compose-testing.yml exec -T api python manage.py importall --cruise_name en617 | |
| docker compose -f docker-compose-testing.yml exec -T api python manage.py importall --cruise_name hrs2303 | |
| docker compose -f docker-compose-testing.yml exec -T api python manage.py importall --cruise_name ae2426 | |
| docker compose -f docker-compose-testing.yml exec -T api python manage.py importall --cruise_name at46 | |
| # Run automated tests | |
| docker compose -f docker-compose-testing.yml run -e GITHUB_ACTIONS=true tests ./RunAllTests-Docker.bat | |
| - name: Build, Tag & Push Production Image | |
| if: contains(github.ref, 'main') | |
| run: | | |
| echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
| IMAGE_ID=ghcr.io/${{ github.repository }} | |
| IMAGE_ID=$(echo "$IMAGE_ID" | tr '[:upper:]' '[:lower:]') | |
| echo "Fetching existing tags from GHCR..." | |
| EXISTING_TAGS=$(curl -sL \ | |
| -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
| https://api.github.com/orgs/whoigit/packages/container/nes-lter-api-2/versions \ | |
| | jq -r '.[].metadata.container.tags[]' | sort -u) | |
| echo "Existing tags:" | |
| echo "$EXISTING_TAGS" | |
| # Filter numeric or v-prefixed tags like v1, 2, v10 | |
| LAST_TAG=$(echo "$EXISTING_TAGS" | sed 's/^v//' | grep -E '^[0-9]+$' | sort -n | tail -1) | |
| VERSION=$(( ${LAST_TAG:-0} + 1 )) | |
| echo "Last tag: ${LAST_TAG}" | |
| echo "Next version: v${VERSION}" | |
| # Build Production Container | |
| docker build -f Dockerfile -t $IMAGE_ID . | |
| docker tag $IMAGE_ID $IMAGE_ID:v${VERSION} | |
| docker image ls | |
| docker push $IMAGE_ID:v$VERSION | |
| - name: Stopping API 2 application | |
| run: docker compose --file docker-compose-testing.yml down |