GitHub Actions locally is easy-peasy
?? Alexander Karpov
DevOps Engineer, Fullstack Developer, 8 years+, Python, Terraform, Ansible, Kubernetes, Docker, Microservices, CI/CD
When you want to debug your pipeline using GitHub Actions you may use a tool for running this in local. It gives you opportunity do debugging without any commits to your repo. It is really helpful and easy!
Just do install and use ?act? https://nektosact.com/introduction.html
Instruction for MacBook based on M2 Chip
?? You must have Homebrew and Docker Engine pre-installed
The example how to use act for building and pushing Docker images to GitHub Packages.
Step 1: Installing act
brew install act
Step 2: Prepare your workflow
Open git project directory and create workflow
mkdir -p .github/workflows
Create build.yml
touch .github/workflows/build.yml
name: Build
on: push
jobs:
build:
name: Build push Docker image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and push
run: |
docker login --username ${{ secrets.GHCR_USER }} --password ${{ secrets.GHCR_TOKEN }} ghcr.io
docker build . --tag ghcr.io/${{ secrets.GHCR_USER }}/application:latest
docker push ghcr.io/${{ secrets.GHCR_USER }}/application:latest
Create a base Dockerfile for your build
echo "FROM alpine" >> Dockerfile
Step 3: Create file with your secrets
touch .secrets
echo .secrets >> .gitignore
GHCR_TOKEN=ghp_c....91B
GHCR_USER=username
You have to create the token here https://github.com/settings/tokens (use classic token with rw-permissions for packages)
Step 4: Run act
act push --container-architecture=linux/arm64 --secret-file .secrets
Sample output:
?? Good job! Your runner was executed locally and it had no affect to commit history of your repository!