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

FR-0000 - Adding shared action for build and publish docker image #3

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
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
42 changes: 42 additions & 0 deletions .github/shared-actions/build-and-publish-docker/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Build and publish docker
description: This action should Build a docker image and publish to docker hub
inputs:
short_sha:
description: 'Git commit SHA'
required: true
build_image_script:
description: 'The shell script that builds the docker image'
required: true
default: ./ci/build-and-publish-image.sh
npm_token:
description: 'Npm Token'
required: true
docker_hub_password:
description: 'Docker Hub Password'
required: true
docker_hub_user:
description: 'Docker Hub User'
required: true



runs:
using: "composite"
steps:
- name: Display Current Tag/SHA
run: echo Tag/SHA ${{ inputs.short_sha }}
shell: bash
- name: Build and push docker image
run: |
echo commit hash: ${COMMIT_HASH}
echo tag: ${TAG_NAME}
echo branch: ${BRANCH_NAME}
sudo chmod +x ${{ inputs.build_image_script }}
${{ inputs.build_image_script }}
shell: bash
env:
COMMIT_HASH: ${{ inputs.short_sha }}
TAG_NAME: ${{ github.ref_name }}
NPM_TOKEN: ${{ inputs.npm_token }}
DOCKER_HUB_USER: ${{ inputs.docker_hub_user }}
DOCKER_HUB_PASSWORD: ${{ inputs.docker_hub_password }}
59 changes: 59 additions & 0 deletions .github/workflows/api-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: API tests job

on:
workflow_call:
inputs:
build_image_script:
required: false
default: ./ci/build-and-publish-image.sh
type: string
secrets:
npm_token:
description: 'Npm Token'
required: true
docker_hub_password:
description: 'Docker Hub Password'
required: true
docker_hub_user:
description: 'Docker Hub User'
required: true


jobs:
params:
name: Prepare Parmas
runs-on: ubuntu-latest
outputs:
short_sha: ${{ steps.short-sha.outputs.short_sha }}
steps:
- name: Parse short sha
id: short-sha
run: |
if [ -z "${{ inputs.tag }}" ]
then
echo "::set-output name=short_sha::${GITHUB_SHA::7}"
else
echo "::set-output name=short_sha::$(${{ inputs.tag }})"
fi

build-and-publish-docker:
name: Build and publish docker image
runs-on: ubuntu-latest
needs: [ params ]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Checkout workflows
uses: actions/checkout@v3
with:
repository: frontegg/workflows
path: workflows
- name: build and publish docker image
uses: ./workflows/.github/shared-actions/build-and-publish-docker
with:
short_sha: ${{ needs.params.outputs.short_sha }}
build_image_script: ${{ inputs.build_image_script }}
npm_token: ${{secrets.npm_token}}
docker_hub_user: ${{ secrets.docker_hub_user }}
docker_hub_password: ${{ secrets.docker_hub_password }}

31 changes: 15 additions & 16 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,26 @@ jobs:
build-and-publish-docker:
name: Build and publish docker image
runs-on: ubuntu-latest
needs: [params]
needs: [ params ]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Display Current Tag/SHA
run: echo Tag/SHA ${{ needs.params.outputs.short_sha }}
shell: bash
- name: Checkout
- name: Checkout workflows
uses: actions/checkout@v3
- name: Build and push docker image
run: |
echo commit hash: ${COMMIT_HASH}
echo tag: ${TAG_NAME}
echo branch: ${BRANCH_NAME}
sudo chmod +x ${{ inputs.build_image_script }}
${{ inputs.build_image_script }}
shell: bash
env:
COMMIT_HASH: ${{ needs.params.outputs.short_sha }}
NPM_TOKEN: ${{ secrets.npm_token }}
TAG_NAME: ${{ github.ref_name }}
DOCKER_HUB_USER: ${{ secrets.docker_hub_user }}
DOCKER_HUB_PASSWORD: ${{ secrets.docker_hub_password }}
with:
repository: frontegg/workflows
path: workflows
- name: build and publish docker image
uses: ./workflows/.github/shared-actions/build-and-publish-docker
with:
short_sha: ${{ needs.params.outputs.short_sha }}
build_image_script: ${{ inputs.build_image_script }}
npm_token: ${{secrets.npm_token}}
docker_hub_user: ${{ secrets.docker_hub_user }}
docker_hub_password: ${{ secrets.docker_hub_password }}

build-and-publish-hybrid-docker:
name: Build and publish hybrid docker image
Expand Down