Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push to quay and ghcr #9

Merged
merged 1 commit into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 52 additions & 23 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -1,36 +1,65 @@
name: Publish Docker image
name: Publish docker image

on:
release:
types: [published]

env:
GHCR_CONTAINER: ghcr.io/${{ github.repository }}
QUAY_CONTAINER: quay.io/${{ github.repository }}

jobs:
push_to_registry:
name: Push Docker image to GitHub Container Registry
build-and-push-image:
runs-on: ubuntu-latest
steps:
permissions:
contents: read
packages: write

- name: Check out the repo
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Get release version
id: release
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
- name: Docker Login to ghcr
uses: docker/login-action@v1.12.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker Login to quay
uses: docker/login-action@v1.12.0
with:
registry: quay.io
username: ${{ secrets.QUAY_GITHUB_ACTION_PUSH_USERNAME }}
password: ${{ secrets.QUAY_GITHUB_ACTION_PUSH_PASSWORD }}

- name: Get docker tag
run: echo "::set-output name=docker_tag::${{ github.ref_name }}"
id: docker_tag

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Download latest earthly
run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/download/v0.6.2/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'"
- name: Earthly version
run: earthly --version

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Run build and publish to ghcr
run: earthly --ci --push +publish --TAG=${{ steps.docker_tag.outputs.docker_tag }} --CONTAINER=${{ env.GHCR_CONTAINER }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
username: ${{ github.repository_owner }}
password: ${{ secrets.APPKNOX_GITHUB_CONTAINER_TOKEN }} #encrypted secret var
registry: ghcr.io
- name: Run build and publish to quay
run: earthly --ci --push +publish --TAG=${{ steps.docker_tag.outputs.docker_tag }} --CONTAINER=${{ env.QUAY_CONTAINER }}

- name: Build & Push to GitHub Container Registry
uses: docker/build-push-action@v2
- name: Slack notification
if: always()
uses: 8398a7/action-slack@v3
with:
context: .
push: true
tags: ghcr.io/${{ github.repository }}:${{ steps.release.outputs.VERSION }}
status: custom
fields: repo,workflow
custom_payload: |
{
attachments: [{
color: '${{ job.status }}' === 'success' ? 'good' : '${{ job.status }}' === 'failure' ? 'danger' : 'warning',
text: `Docker image creation ${{ job.status }}: ${{ env.GHCR_CONTAINER }}:${{ steps.docker_tag.outputs.docker_tag }} and ${{ env.QUAY_CONTAINER }}:${{ steps.docker_tag.outputs.docker_tag }}`,
}]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
15 changes: 15 additions & 0 deletions Earthfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
VERSION 0.6

ARG EARTHLY_GIT_BRANCH
ARG EARTHLY_GIT_SHORT_HASH
ARG TAG="$EARTHLY_GIT_BRANCH"_"$EARTHLY_GIT_SHORT_HASH"
ARG CONTAINER="ghcr.io/appknox/stupid-socket"

docker:
FROM DOCKERFILE .
SAVE IMAGE stupid-socket:"$TAG"

publish:
FROM DOCKERFILE .
FROM +docker
SAVE IMAGE --push "$CONTAINER":"$TAG"
Loading