Skip to content

Commit

Permalink
push image to dockerhub action (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
AJarombek authored Jan 13, 2024
1 parent 0821695 commit 5bf8e9a
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and Push Docker Images
name: Build and Push Docker Images to AWS ECR

on:
workflow_dispatch:
Expand Down
62 changes: 62 additions & 0 deletions .github/workflows/push_test_images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Build and Push Docker Image to DockerHub

on:
workflow_dispatch:
image:
description: 'Docker image to build and push'
required: true
type: choice
default: 'saints-xctf-api-cicd'
options:
- saints-xctf-api-cicd
version:
description: 'Version of the Docker image to build and push'
type: string
required: true
default: '0.0.0'
is_latest:
description: 'Whether the Docker image is the latest version'
type: boolean
required: true
default: true

jobs:
build-and-push-docker-image:
runs-on: ubuntu-latest
timeout-minutes: 15

steps:
- name: Checkout Repository
id: checkout-repository
uses: actions/checkout@v3

- name: Login to DockerHub
id: login-dockerhub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Set Dockerfile
id: set-dockerfile
run: echo "dockerfile=cicd.test.dockerfile" >> $GITHUB_ENV

- name: Build Docker Image
id: build-docker-image
working-directory: api/src
run: |
docker build -t ${{ github.event.inputs.image }}:${{ github.run_number }} -f ${{ env.dockerfile }} .
docker tag ${{ github.event.inputs.image }}:${{ github.run_number }} ajarombek/${{ github.event.inputs.image }}:${{ github.event.inputs.version }}
docker tag ${{ github.event.inputs.image }}:${{ github.run_number }} ajarombek/${{ github.event.inputs.image }}:${{ github.run_number }}
- name: Push Docker Image
id: push-docker-image
working-directory: api/src
run: |
docker push ajarombek/${{ github.event.inputs.image }}:${{ github.event.inputs.version }}
docker push ajarombek/${{ github.event.inputs.image }}:${{ github.run_number }}
if [ ${{ github.event.inputs.is_latest }} == "true" ]; then
docker tag ${{ github.event.inputs.image }}:${{ github.run_number }} ajarombek/${{ github.event.inputs.image }}:latest
docker push ajarombek/${{ github.event.inputs.image }}:latest
fi

0 comments on commit 5bf8e9a

Please sign in to comment.