Created
May 4, 2022 12:18
-
-
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)
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
# 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