Create main.yml #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "dhohirp" --password-stdin | ||
- name: Push Docker image to Docker Hub | ||
run: | | ||
docker tag $REPO_NAME "dhohirp/$REPO_NAME" | ||
docker push "dhohirp/$REPO_NAME" |