Highly ambitious ATProtocol AppView service and sdks
138
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 158 lines 4.7 kB view raw
1name: Build and Deploy Slices API 2 3on: 4 workflow_dispatch: 5 pull_request: 6 branches: [main] 7 paths: ["api/**", "crates/slices-lexicon/**"] 8 push: 9 branches: [main] 10 paths: ["api/**", "crates/slicese-lexicon/**"] 11 12jobs: 13 build: 14 runs-on: ubuntu-latest 15 defaults: 16 run: 17 working-directory: api 18 19 steps: 20 - name: Checkout code 21 uses: actions/checkout@v4 22 23 - name: Install Nix 24 uses: DeterminateSystems/nix-installer-action@main 25 with: 26 logger: pretty 27 28 - name: Setup Nix cache 29 uses: DeterminateSystems/magic-nix-cache-action@main 30 31 - name: Check flake 32 run: nix flake check --refresh 33 34 - name: Build Rust binary 35 run: nix build .#slices 36 37 - name: Build Docker image 38 run: nix build .#slicesImg 39 40 - name: Load Docker image 41 run: docker load < result 42 43 - name: Start PostgreSQL for testing 44 run: | 45 docker run -d --name postgres-test \ 46 -e POSTGRES_DB=slice_test \ 47 -e POSTGRES_USER=slice \ 48 -e POSTGRES_PASSWORD=slice_test_password \ 49 -p 5432:5432 \ 50 postgres:15 51 52 # Wait for PostgreSQL to start 53 sleep 10 54 55 - name: Test Docker image 56 run: | 57 # Check PostgreSQL is running 58 echo "Checking PostgreSQL status..." 59 docker ps | grep postgres-test 60 docker logs postgres-test 61 62 # Test PostgreSQL connection 63 echo "Testing PostgreSQL connection..." 64 docker exec postgres-test psql -U slice -d slice_test -c "SELECT version();" 65 66 # Start the Slice container with PostgreSQL backend 67 echo "Starting Slice container..." 68 docker run -d --name slice-test -p 8080:8080 \ 69 -e HTTP_PORT=8080 \ 70 -e DATABASE_URL=postgresql://slice:slice_test_password@host.docker.internal:5432/slice_test \ 71 --add-host host.docker.internal:host-gateway \ 72 slices:latest 73 74 # Wait for the service to start and show logs 75 echo "Waiting for service to start..." 76 sleep 10 77 78 echo "Checking all containers (including exited)..." 79 docker ps -a | grep -E "(slice-test|postgres-test)" || true 80 81 echo "Checking Slice container status..." 82 docker ps | grep slice-test || echo "Slice container not running!" 83 84 echo "Slice container logs:" 85 docker logs slice-test 2>&1 || echo "Failed to get logs" 86 87 echo "Checking if slice container exited:" 88 docker inspect slice-test --format='{{.State.Status}}' || echo "Container not found" 89 docker inspect slice-test --format='{{.State.ExitCode}}' || echo "No exit code" 90 91 # Additional wait 92 sleep 10 93 94 echo "Final Slice container logs:" 95 docker logs slice-test 2>&1 || echo "Failed to get final logs" 96 97 # Test the root endpoint with verbose output 98 echo "Testing root endpoint..." 99 curl -v -f http://localhost:8080 || { 100 echo "Curl failed, showing final logs:" 101 docker logs slice-test 102 docker logs postgres-test 103 exit 1 104 } 105 106 # Stop test containers 107 docker stop slice-test postgres-test 108 docker rm slice-test postgres-test 109 110 - name: Save Docker image as artifact 111 run: docker save slices:latest | gzip > slice-image.tar.gz 112 113 - name: Upload Docker image artifact 114 uses: actions/upload-artifact@v4 115 with: 116 name: slice-docker-image 117 path: api/slice-image.tar.gz 118 retention-days: 1 119 120 deploy: 121 # if: github.ref == 'refs/heads/main' 122 needs: build 123 runs-on: ubuntu-latest 124 defaults: 125 run: 126 working-directory: api 127 128 steps: 129 - name: Checkout code 130 uses: actions/checkout@v4 131 132 - name: Download Docker image artifact 133 uses: actions/download-artifact@v4 134 with: 135 name: slice-docker-image 136 path: api/ 137 138 - name: Load Docker image 139 run: docker load < slice-image.tar.gz 140 141 - name: Tag for Fly.io 142 run: docker tag slices:latest registry.fly.io/slices-api:latest 143 144 - name: Setup Fly CLI 145 uses: superfly/flyctl-actions/setup-flyctl@master 146 147 - name: Login to Fly.io registry 148 run: flyctl auth docker 149 env: 150 FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} 151 152 - name: Push to Fly.io registry 153 run: docker push registry.fly.io/slices-api:latest 154 155 - name: Deploy to Fly.io 156 run: flyctl deploy --image registry.fly.io/slices-api:latest 157 env: 158 FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}