continuous-integrationgithub-actionscontinuous-deploymentbuildpack

Build image with buildpacks from procfile with github actions


So I just migrated from Cloud Shell-Google Cloud to build a docker image.

What I did and was worked fine is with this simple command:

pack build my-app-image --builder gcr.io/buildpacks/builder:v1 --path .

While my Procfile is simply this:

web: uvicorn main:app --host=0.0.0.0 --port=${PORT:-8080} --app-dir ./src

Where --path . is my current repository project that has been pulled with git pull.

How to construct workflows.yaml for github actions?


Solution

  • name: Build and Deploy with Buildpacks
    
    on:
      push:
        branches:
          - main  # Trigger the workflow on push to the main branch
      pull_request:
        branches:
          - main  # Trigger the workflow on pull requests to the main branch
    
    jobs:
      build:
        runs-on: ubuntu-latest
    
        steps:
        - name: Checkout repository
          uses: actions/checkout@v2
    
        - name: Install Pack CLI
          run: |
            sudo add-apt-repository ppa:cncf-buildpacks/pack-cli
            sudo apt-get update
            sudo apt-get install pack-cli
    
        - name: Log in to Docker Hub
          uses: docker/login-action@v2
          with:
            username: ${{ secrets.DOCKER_USERNAME }}
            password: ${{ secrets.DOCKER_PASSWORD }}
    
        - name: Build and push Docker image using Buildpacks
          run: |
            pack build ${{ secrets.DOCKER_USERNAME }}/my-image --builder gcr.io/buildpacks/builder:v1 --path .
            docker push ${{ secrets.DOCKER_USERNAME }}/my-image:latest
    

    For rust language, I use this:

    name: Rust - Buildpack
    
    on:
      push:
        branches: [ "master" ]
      pull_request:
        branches: [ "master" ]
    
    env:
      CARGO_TERM_COLOR: always
    
    jobs:
      build:
    
        runs-on: ubuntu-latest
    
        steps:
        - uses: actions/checkout@v4
          
        - name: Install Pack CLI
          uses: buildpacks/github-actions/setup-pack@v5.0.0
        
        - name: Log in to Docker Hub
          uses: docker/login-action@v2
          with:
            username: ${{ secrets.DOCKER_USERNAME }}
            password: ${{ secrets.DOCKER_PASSWORD }}
        
        - name: Build and push Docker image using Buildpacks
          run: |
            pack build ${{ secrets.DOCKER_USERNAME }}/rust-rocket-buildpacks --buildpack docker.io/paketocommunity/rust --builder paketobuildpacks/builder-jammy-full --path .
            docker push ${{ secrets.DOCKER_USERNAME }}/rust-rocket-buildpacks:latest