Skip to content

Commit

Permalink
Create main.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
dhohirpradana authored Jan 15, 2024
1 parent 5d644fc commit 8402fc5
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Docker Hub CI

on:
push:
branches: ["master"]
pull_request:
branches: ["master"]

jobs:
build_and_publish:
runs-on: ubuntu-latest

env:
REPO_NAME: ${GITHUB_REPOSITORY#$GITHUB_REPOSITORY_OWNER/}

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set ENV variables
run: |
echo "REPO_NAME=${GITHUB_REPOSITORY#$GITHUB_REPOSITORY_OWNER/}" >> $GITHUB_ENV
- name: Build the Docker image
run: docker build . --file Dockerfile --tag $REPO_NAME

- name: Login to Docker Hub
run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin

- name: Push Docker image to Docker Hub
run: |
docker tag $REPO_NAME "${{ secrets.DOCKERHUB_USERNAME }}/$REPO_NAME"
docker push "${{ secrets.DOCKERHUB_USERNAME }}/$REPO_NAME"

0 comments on commit 8402fc5

Please sign in to comment.