Deploy to Production (main) #99
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy to Production (main) | |
| on: | |
| schedule: | |
| - cron: '0 6 * * *' # 6am UTC daily | |
| push: | |
| branches: [main] | |
| workflow_dispatch: | |
| workflow_call: | |
| permissions: | |
| contents: read | |
| jobs: | |
| deploy: | |
| runs-on: self-hosted | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Generate version file | |
| run: | | |
| mkdir -p ./static/data | |
| TZ=UTC git show -s --date=iso-local --format='%h %cd' HEAD > ./static/data/version | |
| - name: Build Zola site | |
| run: zola build --base-url="https://${{ vars.LIBP2P_DOMAIN }}/" | |
| - name: Install ipfs-car | |
| run: npm install -g ipfs-car | |
| - name: Create CAR archive of public folder | |
| run: ipfs-car pack ./public --output libp2p.car | |
| - name: Configure AWS credentials for Filebase | |
| env: | |
| AWS_ACCESS_KEY_ID: ${{ secrets.FILEBASE_ACCESS_KEY }} | |
| AWS_SECRET_ACCESS_KEY: ${{ secrets.FILEBASE_SECRET_KEY }} | |
| AWS_DEFAULT_REGION: us-east-1 # Filebase ignores region, but required | |
| run: | | |
| echo "AWS credentials exported as env vars" | |
| aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID | |
| aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY | |
| aws configure set default.region $AWS_DEFAULT_REGION | |
| aws configure list | |
| - name: Upload CAR to production bucket (with import=car) | |
| id: upload | |
| env: | |
| AWS_EC2_METADATA_DISABLED: true | |
| run: | | |
| aws --endpoint https://s3.filebase.com \ | |
| s3 cp libp2p.car \ | |
| s3://${{ vars.FILEBASE_BUCKET_PROD }}/ \ | |
| --metadata 'import=car' | |
| aws --endpoint https://s3.filebase.com \ | |
| s3api head-object \ | |
| --bucket ${{ vars.FILEBASE_BUCKET_PROD }} \ | |
| --key libp2p.car > head-object.log 2>&1 | |
| # Extract CID from debug log (x-amz-meta-cid header) | |
| CID=$(jq -r .Metadata.cid head-object.log | tr -d '\r') | |
| if [ -z "$CID" ]; then | |
| echo "Failed to extract CID from upload response" | |
| cat head-object.log | |
| exit 1 | |
| fi | |
| echo "cid=$CID" >> $GITHUB_OUTPUT | |
| - name: Publish IPNS record | |
| run: | | |
| curl -X POST \ | |
| -H "Authorization: Bearer ${{ secrets.FILEBASE_IPFS_RPC_API_KEY }}" \ | |
| "https://rpc.filebase.io/api/v0/name/publish?arg=/ipfs/${{ steps.upload.outputs.cid }}&key=libp2p.myfilebase.site&ttl=1m" | |
| curl -X POST \ | |
| -H "Authorization: Bearer ${{ secrets.FILEBASE_IPFS_RPC_API_KEY }}" \ | |
| "https://rpc.filebase.io/api/v0/name/publish?arg=/ipfs/${{ steps.upload.outputs.cid }}&key=docs-libp2p.myfilebase.site&ttl=1m" | |
| curl -X POST \ | |
| -H "Authorization: Bearer ${{ secrets.FILEBASE_IPFS_RPC_API_KEY }}" \ | |
| "https://rpc.filebase.io/api/v0/name/publish?arg=/ipfs/${{ steps.upload.outputs.cid }}&key=connectivity-libp2p.myfilebase.site&ttl=1m" | |
| curl -X POST \ | |
| -H "Authorization: Bearer ${{ secrets.FILEBASE_IPFS_RPC_API_KEY }}" \ | |
| "https://rpc.filebase.io/api/v0/name/publish?arg=/ipfs/${{ steps.upload.outputs.cid }}&key=blog-libp2p.myfilebase.site&ttl=1m" | |
| - name: Announce production deployment | |
| run: | | |
| echo "::notice title=Production Deployed::" | |
| echo "Version: $(cat ./static/data/version)" | |
| echo "Root CID: ${{ steps.upload.outputs.cid }}" | |
| echo "View site: https://libp2p.myfilebase.site/" | |
| # Optional: add IPNS update, GitHub deployment, Slack notification, etc. here |