Skip to content

Updates todo

Updates todo #72

Workflow file for this run

name: node
on:
push:
branches:
- "master"
pull_request:
branches:
- "master"
jobs:
test:
runs-on: ubuntu-latest
services:
redis:
image: redis:6
ports:
- 6379:6379
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build test image
uses: docker/build-push-action@v6
with:
platforms: linux/amd64
target: dev
context: .
load: true
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/blot
cache-to: type=registry,ref=ghcr.io/${{ github.repository_owner }}/blot,mode=max
tags: ghcr.io/${{ github.repository_owner }}/blot:test-${{ github.sha }}
- name: Run tests
env:
BLOT_STRIPE_KEY: ${{ secrets.BLOT_STRIPE_KEY }}
BLOT_STRIPE_SECRET: ${{ secrets.BLOT_STRIPE_SECRET }}
BLOT_STRIPE_PRODUCT: ${{ secrets.BLOT_STRIPE_PRODUCT }}
run: |
docker run --rm \
--network name=${{ job.services.redis.network }} \
-e BLOT_REDIS_HOST=redis \
-e BLOT_STRIPE_KEY=$BLOT_STRIPE_KEY \
-e BLOT_STRIPE_SECRET=$BLOT_STRIPE_SECRET \
-e BLOT_STRIPE_PRODUCT=$BLOT_STRIPE_PRODUCT \
-v ${{ github.workspace }}/app:/usr/src/app/app \
-v ${{ github.workspace }}/scripts:/usr/src/app/scripts \
-v ${{ github.workspace }}/config:/usr/src/app/config \
-v ${{ github.workspace }}/notes:/usr/src/app/notes \
-v ${{ github.workspace }}/todo.txt:/usr/src/app/todo.txt \
-v ${{ github.workspace }}/.git:/usr/src/app/.git \
-v ${{ github.workspace }}/tests:/usr/src/app/tests \
ghcr.io/${{ github.repository_owner }}/blot:test-${{ github.sha }} \
sh -c "node /usr/src/app/app/documentation/build/index.js --no-watch --skip-zip && node tests && npx depcheck --ignores=depcheck,nyc,nodemon,blessed-contrib,fontkit,text-to-svg --skip-missing"
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build production image
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
target: prod
context: .
push: true
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/blot
cache-to: type=registry,ref=ghcr.io/${{ github.repository_owner }}/blot,mode=max
tags: ghcr.io/${{ github.repository_owner }}/blot:${{ github.sha }}
- name: Verify built-in health check
env:
IMAGE: ghcr.io/${{ github.repository_owner }}/blot:${{ github.sha }}
run: |
docker network create test_network
# Start a Redis container
redis_container_id=$(docker run -d --name test_redis --network test_network redis:latest)
# Ensure Redis started successfully
if [ -z "$redis_container_id" ]; then
echo "Failed to start the Redis container. Exiting..."
exit 1
fi
echo "Waiting for Redis ($redis_container_id) to become ready..."
timeout=30
interval=2
elapsed=0
while ! docker exec $redis_container_id redis-cli ping | grep -q PONG; do
if [ $elapsed -ge $timeout ]; then
echo "Redis did not become ready within $timeout seconds. Exiting..."
docker stop $redis_container_id
docker rm $redis_container_id
exit 1
fi
sleep $interval
elapsed=$((elapsed + interval))
done
echo "Redis is ready."
# Start the app container with Redis environment variables
container_id=$(docker run -d --network test_network --env BLOT_REDIS_HOST=test_redis -p 8080:8080 $IMAGE)
# Ensure the app container started successfully
if [ -z "$container_id" ]; then
echo "Failed to start the app container. Exiting..."
docker stop $redis_container_id
docker rm $redis_container_id
exit 1
fi
echo "Waiting for the app container ($container_id) to pass the built-in health check..."
# Wait for the app container's health status to become "healthy"
timeout=60
interval=5
elapsed=0
while [ "$(docker inspect --format='{{json .State.Health.Status}}' $container_id)" != '"healthy"' ]; do
if [ $elapsed -ge $timeout ]; then
echo "Health check failed: app container did not become healthy within $timeout seconds."
echo "Final log contents:"
docker exec $container_id cat /usr/src/app/data/logs/docker/app.log
docker stop $container_id
docker rm $container_id
docker stop $redis_container_id
docker rm $redis_container_id
exit 1
fi
sleep $interval
elapsed=$((elapsed + interval))
done
echo "App container passed the health check."
# Clean up
docker stop $container_id
docker rm $container_id
docker stop $redis_container_id
docker rm $redis_container_id