Skip to content

Publish Images

Publish Images #51

Workflow file for this run

name: Publish Images
on:
workflow_dispatch:
inputs:
gcp:
type: boolean
description: GCP container registry
default: true
aws:
type: boolean
description: AWS ECR container registry
default: true
dockerHub:
type: boolean
description: Docker container registry
default: true
jobs:
Build-and-push:
runs-on: ubuntu-latest
env:
ECR_REPOSITORY: ${{ secrets.AWS_REPO_NAME }}
PUBLIC_ECR_URL: ${{ secrets.AWS_REPO_URL }}
IMAGE_NAME: ${{ secrets.IMAGE_NAME }}
DOCKERHUB_REPOSITORY: ${{ secrets.DOCKERHUB_REPOSITORY }}
GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }}
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
CONTAINER_REGISTRY_FOLDER: ${{ secrets.GCP_CONTAINER_REGISTRY_FOLDER }}
IMAGE_TAG: latest
steps:
- name: Git checkout
uses: actions/checkout@v2
# Build docker image
- name: Build Docker image
id: build-image
run: docker build -t $IMAGE_NAME .
# Login to Public ECR
- name: Login to Public ECR
if: github.event.inputs.aws == 'true'
uses: docker/login-action@v1
with:
registry: public.ecr.aws
username: ${{ secrets.AWS_ACCESS_KEY_ID }}
password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
env:
AWS_REGION: ${{ secrets.AWS_REGION }}
- name: Tag and push the image to Amazon ECR
if: github.event.inputs.aws == 'true'
id: aws-push-image
run: |
docker tag $IMAGE_NAME:$IMAGE_TAG $PUBLIC_ECR_URL/$IMAGE_NAME:$IMAGE_TAG
echo "Pushing image to ECR..."
docker push $PUBLIC_ECR_URL/$IMAGE_NAME:$IMAGE_TAG
echo "::set-output name=image::$PUBLIC_ECR_URL/$IMAGE_NAME:$IMAGE_TAG"
- name: Login to Docker Hub
if: github.event.inputs.dockerHub == 'true'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Tag and push the image to Docker Hub
if: github.event.inputs.dockerHub == 'true'
id: dockerhub-push-image
run: |
docker tag $IMAGE_NAME $DOCKERHUB_REPOSITORY/$IMAGE_NAME:$IMAGE_TAG
echo "Pushing image to Docker Hub..."
docker push $DOCKERHUB_REPOSITORY/$IMAGE_NAME:$IMAGE_TAG
echo "::set-output name=image::$DOCKERHUB_REPOSITORY/$IMAGE_NAME:$IMAGE_TAG"
# Authenticate to Google Cloud
- id: auth
name: Authenticate to Google Cloud
if: github.event.inputs.gcp == 'true'
uses: 'google-github-actions/auth@v0'
with:
credentials_json: '${{ secrets.GCP_SA_KEY }}'
# Set up Cloud SDK
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v0
if: github.event.inputs.gcp == 'true'
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}
# Push image to Google Container Registry
- name: Tag and push image to GCP container registry
if: github.event.inputs.gcp == 'true'
run: |
gcloud auth configure-docker -q
docker tag $IMAGE_NAME:$IMAGE_TAG gcr.io/$GCP_PROJECT_ID/$CONTAINER_REGISTRY_FOLDER
docker push gcr.io/$GCP_PROJECT_ID/$CONTAINER_REGISTRY_FOLDER:$IMAGE_TAG