Skip to content

Commit

Permalink
Add workflow to build docker image on github
Browse files Browse the repository at this point in the history
  • Loading branch information
greenscientist committed Feb 14, 2025
1 parent 7da92a2 commit 09c61e8
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/build-docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Container Build and Push

on:
push:
branches:
- "v2c"
workflow_dispatch:

env:
GITHUB_REGISTRY: ghcr.io
DOCKERHUB_REGISTRY: docker.io
DOCKERHUB_IMAGE: chairemobilite/${{ github.event.repository.name }}
GITHUB_IMAGE: chairemobilite/trrouting

jobs:
# Branch push job - builds and pushes to both registries
branch-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Generate Docker tags for branch
id: branch-meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.DOCKERHUB_REGISTRY }}/${{ env.DOCKERHUB_IMAGE }}
${{ env.GITHUB_REGISTRY }}/${{ env.GITHUB_IMAGE }}
tags: |
# Tag as latest since v2c is the main branch
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/v2c' }}
# Include the branch name as a tag
type=ref,event=branch
- name: Build and push branch images
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.branch-meta.outputs.tags }}
labels: ${{ steps.branch-meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
25 changes: 25 additions & 0 deletions .github/workflows/test-docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: PR Container Build Check

on:
pull_request:
branches:
- "v2c"

jobs:
pr-build-check:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build image
uses: docker/build-push-action@v5
with:
context: .
push: false
load: false
cache-from: type=gha
cache-to: type=gha,mode=max

0 comments on commit 09c61e8

Please sign in to comment.