Skip to content

Instantly share code, notes, and snippets.

@amessinger
Created May 4, 2022 12:18
Show Gist options
  • Save amessinger/1f545cf5fe40c0ef2742d97ac04472e6 to your computer and use it in GitHub Desktop.
Save amessinger/1f545cf5fe40c0ef2742d97ac04472e6 to your computer and use it in GitHub Desktop.
Build and Push image with SSH support (for private git repositories for instance)
# make sure you have SSH_PRIVATE_KEY defined in your Github's repository (or organization) secrets
name: Container image
on:
push:
branches: [ main ]
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Export SSH socket
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set image name
run: echo "image_name=`echo "${{ github.event.repository.full_name }}" | tr '[:upper:]' '[:lower:]'`" >> $GITHUB_ENV
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
ssh: |
default=${{ env.SSH_AUTH_SOCK }}
platforms: linux/amd64,linux/arm64
push: true
tags: |
ghcr.io/${{ env.image_name }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment