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: Build and run Docker container | |
on: | |
push: | |
branches: ["main"] | |
pull_request: | |
branches: ["main"] | |
jobs: | |
build: | |
runs-on: self-hosted | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Build the Docker image | |
run: sudo docker build -t backend . | |
- name: Stop and remove existing container if it exists | |
run: | | |
if [ "$(sudo docker ps -aq -f name=backend)" ]; then | |
sudo docker stop backend | |
sudo docker rm backend | |
fi | |
- name: Run the Docker container on port 8000 | |
run: sudo docker run -d -p 8000:8000 backend |