|
| 1 | +name: Build and Test DAQ System |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ deploy ] |
| 6 | + pull_request: |
| 7 | + branches: [ main, deploy ] |
| 8 | + |
| 9 | +env: |
| 10 | + REGISTRY: ghcr.io |
| 11 | + IMAGE_NAME: ${{ github.repository }} |
| 12 | + |
| 13 | +jobs: |
| 14 | + validate-compose: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: Checkout code |
| 18 | + uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - name: Prepare environment file for CI |
| 21 | + run: | |
| 22 | + if [ ! -f server/installer/.env ]; then |
| 23 | + cp server/installer/.env.example server/installer/.env |
| 24 | + echo "Created .env file from .env.example" |
| 25 | + fi |
| 26 | +
|
| 27 | + - name: Validate docker-compose files |
| 28 | + run: | |
| 29 | + cd server/installer |
| 30 | + docker compose config |
| 31 | + docker compose -f docker-compose.yml config |
| 32 | +
|
| 33 | + build-and-push: |
| 34 | + runs-on: ubuntu-latest |
| 35 | + needs: validate-compose |
| 36 | + permissions: |
| 37 | + contents: read |
| 38 | + packages: write |
| 39 | + |
| 40 | + strategy: |
| 41 | + matrix: |
| 42 | + service: [slackbot, lap-detector, file-uploader] |
| 43 | + |
| 44 | + steps: |
| 45 | + - name: Checkout code |
| 46 | + uses: actions/checkout@v4 |
| 47 | + |
| 48 | + - name: Convert repository name to lowercase |
| 49 | + run: | |
| 50 | + echo "IMAGE_NAME_LOWER=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV |
| 51 | +
|
| 52 | + - name: Log in to Container Registry |
| 53 | + uses: docker/login-action@v3 |
| 54 | + with: |
| 55 | + registry: ${{ env.REGISTRY }} |
| 56 | + username: ${{ github.actor }} |
| 57 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 58 | + |
| 59 | + - name: Extract metadata |
| 60 | + id: meta |
| 61 | + run: | |
| 62 | + echo "tags<<EOF" >> $GITHUB_OUTPUT |
| 63 | + echo "${{ env.REGISTRY }}/${IMAGE_NAME_LOWER}/${{ matrix.service }}:latest" >> $GITHUB_OUTPUT |
| 64 | + echo "${{ env.REGISTRY }}/${IMAGE_NAME_LOWER}/${{ matrix.service }}:${{ github.sha }}" >> $GITHUB_OUTPUT |
| 65 | + echo "EOF" >> $GITHUB_OUTPUT |
| 66 | +
|
| 67 | + - name: Build and push Docker image |
| 68 | + uses: docker/build-push-action@v5 |
| 69 | + with: |
| 70 | + context: ./server/installer/${{ matrix.service }} |
| 71 | + push: true |
| 72 | + tags: ${{ steps.meta.outputs.tags }} |
| 73 | + labels: | |
| 74 | + org.opencontainers.image.title=${{ github.event.repository.name }} |
| 75 | + org.opencontainers.image.description=WFR DAQ System - ${{ matrix.service }} |
| 76 | + org.opencontainers.image.url=${{ github.event.repository.html_url }} |
| 77 | + org.opencontainers.image.source=${{ github.event.repository.html_url }} |
| 78 | + org.opencontainers.image.version=${{ github.sha }} |
| 79 | + org.opencontainers.image.created=${{ steps.meta.outputs.created }} |
| 80 | + org.opencontainers.image.revision=${{ github.sha }} |
| 81 | +
|
| 82 | + test-compose: |
| 83 | + runs-on: ubuntu-latest |
| 84 | + needs: build-and-push |
| 85 | + steps: |
| 86 | + - name: Checkout code |
| 87 | + uses: actions/checkout@v4 |
| 88 | + |
| 89 | + - name: Set up Docker Buildx |
| 90 | + uses: docker/setup-buildx-action@v3 |
| 91 | + |
| 92 | + - name: Create .env file for testing |
| 93 | + run: | |
| 94 | + cd server/installer |
| 95 | + cp .env.example .env |
| 96 | + mkdir -p .ci-slicks/src/slicks |
| 97 | + cat > .ci-slicks/pyproject.toml <<'EOF' |
| 98 | + [project] |
| 99 | + name = "slicks" |
| 100 | + version = "0.0.0" |
| 101 | + [build-system] |
| 102 | + requires = ["setuptools>=68"] |
| 103 | + build-backend = "setuptools.build_meta" |
| 104 | + [tool.setuptools.packages.find] |
| 105 | + where = ["src"] |
| 106 | + EOF |
| 107 | + touch .ci-slicks/README.md |
| 108 | + echo '__version__ = "0.0.0"' > .ci-slicks/src/slicks/__init__.py |
| 109 | + echo "SLICKS_HOST_PATH=${PWD}/.ci-slicks" >> .env |
| 110 | +
|
| 111 | + - name: Pull pre-built images |
| 112 | + run: | |
| 113 | + docker pull timescale/timescaledb:latest-pg16 |
| 114 | + docker pull grafana/grafana |
| 115 | + docker pull telegraf:1.30 |
| 116 | + docker pull nginx:alpine |
| 117 | +
|
| 118 | + - name: Build test images |
| 119 | + run: | |
| 120 | + cd server/installer |
| 121 | + docker compose build --parallel |
| 122 | +
|
| 123 | + - name: Validate compose configuration |
| 124 | + run: | |
| 125 | + cd server/installer |
| 126 | + docker compose config --quiet |
| 127 | +
|
| 128 | + - name: Test container startup (quick smoke test) |
| 129 | + run: | |
| 130 | + cd server/installer |
| 131 | + # Start core monitoring stack to ensure compose wiring is valid |
| 132 | + timeout 60s docker compose up timescaledb file-uploader grafana frontend || true |
| 133 | + # Check if containers started (even if they exit quickly) |
| 134 | + docker compose ps |
| 135 | +
|
| 136 | + cleanup: |
| 137 | + runs-on: ubuntu-latest |
| 138 | + needs: [validate-compose, build-and-push, test-compose] |
| 139 | + if: always() |
| 140 | + steps: |
| 141 | + - name: Checkout code |
| 142 | + uses: actions/checkout@v4 |
| 143 | + |
| 144 | + - name: Clean up Docker resources |
| 145 | + run: | |
| 146 | + docker system prune -f |
| 147 | + docker image prune -f |
0 commit comments