Skip to content

add github actions to build image #420

add github actions to build image

add github actions to build image #420

Workflow file for this run

name: CI/CD pipeline
on: push
jobs:
test:
name: test
runs-on: ubuntu-22.04
steps:
- name: checkout-repo
uses: actions/checkout@master
- name: test-image
run: bin/ci
build:
name: Build image and push to Gihub Registry (production branch only)
needs: test
runs-on: ubuntu-latest
steps:
# Step 1: Check out the repository
- name: Checkout code
uses: actions/checkout@v3
# Step 2: Set up Docker Buildx (for cross-platform builds, if needed)
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# Step 3: Log in to GitHub Container Registry
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Step 4: Build the Docker image
- name: Build Docker image
run: |
docker build -t ghcr.io/${{ github.repository }}:${{ github.sha }} .
# Step 5: Push the Docker image to GitHub Container Registry
- name: Push Docker image to GitHub Container Registry
run: |
docker push ghcr.io/${{ github.repository }}:${{ github.sha }}
# Optional Step 6: Add latest tag and push it as well
- name: Tag image as latest and push
run: |
docker tag ghcr.io/${{ github.repository }}:${{ github.sha }} ghcr.io/${{ github.repository }}:latest
docker push ghcr.io/${{ github.repository }}:latest
if: github.ref == 'refs/heads/production'