Docker Image Build And Deploy #9
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 Image Build And Deploy | |
on: | |
workflow_dispatch: # Manual trigger | |
jobs: | |
docker: | |
env: | |
IMAGE_NAME: 'fujikomalan/flask-github' | |
runs-on: self-hosted # Use self-hosted runner | |
steps: | |
- name: Checking Docker Installation | |
run: | | |
docker version | |
- name: Checkout Repository | |
uses: actions/checkout@v4 # Checkout code | |
- name: Docker Login | |
uses: docker/login-action@v2 # Docker login action | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} # Your Docker Hub username stored in secrets | |
password: ${{ secrets.DOCKER_PASSWORD }} # Your Docker Hub password or token stored in secrets | |
- name: Build Docker Image | |
run: | | |
# Use GITHUB_SHA for the commit ID tag | |
docker image build -t ${{env.IMAGE_NAME}}:latest -t ${{env.IMAGE_NAME}}:${{github.sha}} . | |
- name: Push Docker Image | |
run: | | |
docker image push ${{env.IMAGE_NAME}}:latest | |
docker image push ${{env.IMAGE_NAME}}:${{github.sha}} | |
- name: Running Docker Container | |
run: | | |
docker container run -d --name flaskapp -p 8080:5000 ${{env.IMAGE_NAME}}:latest |