Automate the docker image build and deploy to Koyeb
I was trying to automate the build and the deployment of my app docker image to koyeb through the koyeb.deploy.ym action file in my GitHub. I set up correctly my secrets (for docker hub and koyeb in Github secrets.).
I was hitting an error again and again, trying to install the koyeb cli to be used by the runner.
Ok my mistake was to try to use the Koyeb CLI directly in actions.
- using koyeb-community/koyeb-actions@v2 with koyeb/action-git-deploy@v1 solved it.
- I had a bit of a headache to solve an issue with a secret not being the right type but I ended up doing when trying to update the service (doing a new push to main).
I typed :
koyeb secret list
and took the DOCKER-REPO-SECRET that was created apparently when I created the service with the first push.
No I can smoothly deploy my updates from my local dev to my staging in koyeb.
This is how the file ended up :
name: Deploy to Koyeb
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Build and push Docker image
id: docker_build
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/duckdb-spawn:${{ github.sha }}
# Did this as I got errors from the script trying to access the image.
- name: Debug - Verify image exists
run: |
echo "Checking image: ${{ secrets.DOCKER_HUB_USERNAME }}/duckdb-spawn:${{ github.sha }}"
docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/duckdb-spawn:${{ github.sha }}
echo "Image details:"
docker inspect ${{ secrets.DOCKER_HUB_USERNAME }}/duckdb-spawn:${{ github.sha }}
- name: Configure Koyeb
uses: koyeb-community/koyeb-actions@v2
with:
api_token: "${{ secrets.KOYEB_API_TOKEN }}"
- name: Deploy on Koyeb
uses: koyeb/action-git-deploy@v1
with:
app-name: duckdb-spawn
service-name: api
service-type: web
docker: docker.io/${{ secrets.DOCKER_HUB_USERNAME }}/duckdb-spawn:${{ github.sha }}
service-env: DATABASE_URL=/data/duckdb_spawn.db,PYTHONUNBUFFERED=1,LOG_LEVEL=info,ENVIRONMENT=staging
service-ports: 8000:http
service-routes: /:8000
service-instance-type: nano
service-regions: fra
service-checks: 8000:http:/monitoring/health
docker-private-registry-secret: DOCKER_REPO_SECRET
The project is public (it is some fiddling aroun data products) at