Skip to content

Commit

Permalink
Smoke test for build container.
Browse files Browse the repository at this point in the history
  • Loading branch information
antarcticrainforest committed Mar 15, 2024
1 parent 89c4161 commit 15694b5
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/ci_job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,39 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/build/html

build-docker-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up services
run: |
docker-compose -f dev-env/docker-compose.yaml up -d --remove-orphans
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Build freva-storage-service image
uses: docker/build-push-action@v4
with:
platforms: linux/amd64
push: false
load: true
tags: freva-storage-service

- name: Check freva-storage-service image
run: python3 dev-env/check-container.py


dependabot:
name: Merge PR by dependabot
runs-on: ubuntu-latest
Expand Down
58 changes: 58 additions & 0 deletions dev-env/check-container.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""Simple script to start and stop the storage service."""

import logging
import subprocess
import time
import urllib.request
from pathlib import Path

# Set up logging
logging.basicConfig(
format="%(name)s - %(levelname)s - %(message)s",
datefmt="[%X]",
level=logging.INFO,
)
logger = logging.getLogger("container-check")


def check_container(container_name: str = "databrowser") -> None:
"""Check if the contianer starts up."""
try:
process = subprocess.Popen(
[
"docker",
"run",
"--net=host",
"-e",
"MONGO_USER=mongo",
"-e",
"MONGO_PASSWORD=secret",
"-e",
"MONGO_HOST=localhost:27017",
"-e",
"API_PORT=8080",
"-e",
"API_WORKER=8",
"-e",
"MONGO_DB=search_stats",
container_name,
],
)
time.sleep(5)
if process.poll() is not None:
raise RuntimeError("Container died.")
res = urllib.request.Request(
"http://localhost:8080/api/databrowser/overview",
)
with urllib.request.urlopen(res) as response:
if response.getcode() != 200:
raise RuntimeError("Container not properly set up.")
except Exception as error:
logger.critical("Strting the container failed: %s", error)
raise
process.terminate()
logger.info("Container seems to work!")


if __name__ == "__main__":
check_container()

0 comments on commit 15694b5

Please sign in to comment.