Docker build image #90
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
name: Docker build image | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 0 * * 0' | |
push: | |
branches: | |
- main # Trigger CI on main branch | |
paths: | |
- 'Dockerfile' | |
- '.github/workflows/docker build.yml' | |
- 'Modules/*' | |
pull_request: | |
branches: | |
- main # Trigger gated pipeline on PR to main | |
paths: | |
- 'Dockerfile' | |
- '.github/workflows/docker build.yml' | |
- 'Modules/*' | |
env: | |
IMAGE_NAME: fc_powershell | |
jobs: | |
build-and-push-image: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Log in to the Github Container registry | |
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Login to DockerHub | |
uses: docker/login-action@v2 | |
with: | |
username: bmcclure89 | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@507c2f2dc502c992ad446e3d7a5dfbe311567a96 | |
with: | |
tags: | | |
type=ref,event=pr | |
type=ref,event=branch | |
type=sha,format=long | |
type=raw,value=latest | |
images: | | |
ghcr.io/brandonmcclure/${{ env.IMAGE_NAME }} | |
bmcclure89/${{ env.IMAGE_NAME }} | |
- name: Build Docker image (non main branch) | |
uses: docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825 | |
if: github.ref != 'refs/heads/main' | |
with: | |
context: . | |
load: true | |
push: false | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
- name: Build and push Docker image (main branch) | |
uses: docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825 | |
if: github.ref == 'refs/heads/main' | |
with: | |
context: . | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
- id: lowercaseImageName | |
uses: ASzc/change-string-case-action@v5 | |
with: | |
string: bmcclure89/${{ env.IMAGE_NAME }} | |
- name: Save Docker Image archive to local filesystem | |
run: "docker save --output fc_pwsh.tar ${{ steps.lowercaseImageName.outputs.lowercase }}" | |
- name: Upload application's Docker Image as pipeline artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
path: fc_pwsh.tar | |
name: fc_pwsh.tar |