grain.social is a photo sharing platform built on atproto.
at main 108 lines 2.8 kB view raw
1name: Build and Deploy Darkroom 2 3on: 4 workflow_dispatch: 5 pull_request: 6 branches: [ main ] 7 paths: [ 'darkroom/**' ] 8 push: 9 branches: [ main ] 10 paths: [ 'darkroom/**' ] 11 12jobs: 13 build: 14 runs-on: ubuntu-latest 15 defaults: 16 run: 17 working-directory: darkroom 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 33 34 - name: Build Rust binary 35 run: nix build .#darkroom 36 37 - name: Build Docker image 38 run: nix build .#darkroomImg 39 40 - name: Load Docker image 41 run: docker load < result 42 43 - name: Test Docker image 44 run: | 45 # Start the container in the background 46 docker run -d --name darkroom-test -p 8080:8080 darkroom:latest 47 48 # Wait for the service to start 49 sleep 10 50 51 # Test the health endpoint 52 curl -f http://localhost:8080/health || exit 1 53 54 # Stop the test container 55 docker stop darkroom-test 56 docker rm darkroom-test 57 58 - name: Save Docker image as artifact 59 if: github.ref == 'refs/heads/main' 60 run: docker save darkroom:latest | gzip > darkroom-image.tar.gz 61 62 - name: Upload Docker image artifact 63 if: github.ref == 'refs/heads/main' 64 uses: actions/upload-artifact@v4 65 with: 66 name: darkroom-docker-image 67 path: darkroom/darkroom-image.tar.gz 68 retention-days: 1 69 70 deploy: 71 if: github.ref == 'refs/heads/main' 72 needs: build 73 runs-on: ubuntu-latest 74 defaults: 75 run: 76 working-directory: darkroom 77 78 steps: 79 - name: Checkout code 80 uses: actions/checkout@v4 81 82 - name: Download Docker image artifact 83 uses: actions/download-artifact@v4 84 with: 85 name: darkroom-docker-image 86 path: darkroom/ 87 88 - name: Load Docker image 89 run: docker load < darkroom-image.tar.gz 90 91 - name: Tag for Fly.io 92 run: docker tag darkroom:latest registry.fly.io/grain-darkroom:latest 93 94 - name: Setup Fly CLI 95 uses: superfly/flyctl-actions/setup-flyctl@master 96 97 - name: Login to Fly.io registry 98 run: flyctl auth docker 99 env: 100 FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} 101 102 - name: Push to Fly.io registry 103 run: docker push registry.fly.io/grain-darkroom:latest 104 105 - name: Deploy to Fly.io 106 run: flyctl deploy --image registry.fly.io/grain-darkroom:latest 107 env: 108 FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}