fix: use DO docker-credentials API endpoint for proper registry auth #9
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: Build & Push to DO Registry | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| env: | |
| REGISTRY: registry.digitalocean.com | |
| IMAGE_NAME: instalegram/runtime | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Build Docker image (amd64) | |
| run: | | |
| docker build \ | |
| --platform linux/amd64 \ | |
| -t $REGISTRY/$IMAGE_NAME:${{ github.sha }} \ | |
| -t $REGISTRY/$IMAGE_NAME:latest \ | |
| . | |
| - name: Login and push to DO Registry | |
| env: | |
| DO_TOKEN: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} | |
| run: | | |
| # Get a short-lived registry token from DO API | |
| REGISTRY_TOKEN=$(curl -s -u "$DO_TOKEN:" \ | |
| "https://api.digitalocean.com/v2/registry/docker-credentials?read_write=true&expiry_seconds=600" \ | |
| | python3 -c "import json,sys,base64; d=json.load(sys.stdin); auth=d['auths']['registry.digitalocean.com']['auth']; print(base64.b64decode(auth).decode())") | |
| REG_USER=$(echo "$REGISTRY_TOKEN" | cut -d: -f1) | |
| REG_PASS=$(echo "$REGISTRY_TOKEN" | cut -d: -f2-) | |
| echo "$REG_PASS" | docker login registry.digitalocean.com -u "$REG_USER" --password-stdin | |
| docker push $REGISTRY/$IMAGE_NAME:${{ github.sha }} | |
| docker push $REGISTRY/$IMAGE_NAME:latest |