Skip to content

Commit

Permalink
Create build-and-push-docker-image.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
leeevans authored Nov 14, 2024
1 parent 7b43785 commit c1ba986
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions .github/workflows/build-and-push-docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Build Docker image and push to Docker Hub
name: build-and-push-docker-image

on:
workflow_dispatch: # Supports manual triggering
push:
branches: [ main ]

env:
DOCKER_IMAGE: ohdsi/broadsea-atlasdb

jobs:

# Build Docker container and push to Docker Hub
docker:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ env.DOCKER_IMAGE }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Extract Docker metadata (tags, labels)
id: docker_meta
uses: docker/metadata-action@v4
with:
images: ${{ env.DOCKER_IMAGE }}
tags: |
type=semver,pattern={{version}} # Tag based on Git semantic version tag (e.g., "2.2.0")
type=sha # Tag based on commit SHA (e.g., "mycontainer:<commit-sha>")
type=latest # Static "latest" tag
labels: |
org.opencontainers.image.version={{version}}
org.opencontainers.image.source={{source}}
org.opencontainers.image.created={{timestamp}}
org.opencontainers.image.revision={{sha}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

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

- name: Set build parameters
id: build_params
run: |
echo "sha8=${GITHUB_SHA::8}" >> $GITHUB_OUTPUT
echo "push=false" >> $GITHUB_OUTPUT
echo "load=false" >> $GITHUB_OUTPUT
echo "platforms=linux/amd64,linux/arm64" >> $GITHUB_OUTPUT
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Build and push
id: docker_build
uses: docker/build-push-action@v4
with:
context: ./
file: ./Dockerfile
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
platforms: ${{ steps.build_params.outputs.platforms }}
push: ${{ steps.build_params.outputs.push }}
load: ${{ steps.build_params.outputs.load }}
build-args: |
GIT_BRANCH=${{ steps.docker_meta.outputs.version }}
GIT_COMMIT_ID_ABBREV=${{ steps.build_params.outputs.sha8 }}
tags: ${{ steps.docker_meta.outputs.tags }}
labels: |
${{ steps.docker_meta.outputs.labels }}
org.opencontainers.image.authors=Lee Evans - www.ltscomputingllc.com
org.opencontainers.image.vendor=OHDSI
org.opencontainers.image.licenses=Apache-2.0
- name: Log generated Docker image tags
id: log_tags
run: |
echo "Generated tags: ${{ steps.docker_meta.outputs.tags }}"
echo "Generated labels: ${{ steps.docker_meta.outputs.labels }}"
# - name: Inspect image
# run: |
# docker image inspect ${{ env.DOCKER_IMAGE }}:${{ steps.docker_meta.outputs.version }}

0 comments on commit c1ba986

Please sign in to comment.