-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add workflow to build docker image on github
- Loading branch information
1 parent
7da92a2
commit 09c61e8
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |