fix cicd and docker compose file #82
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, push, and deploy Docker image for EventHub API | |
on: | |
push: | |
branches: | |
- master | |
workflow_dispatch: | |
env: | |
REGISTRY: ${{ secrets.SERVER_IP }}:5000 | |
DOCKER_IMAGE_NAME: eventhub-api # Replace with your Docker Hub repo name | |
CONTAINER_NAME: "eventhub.api" | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
with: | |
buildkitd-config-inline: | | |
[registry."$REGISTRY"] | |
http = true | |
insecure = true | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: ./source/EventHub.Presentation/Dockerfile | |
push: true | |
tags: $REGISTRY/eventhub-api:linux-latest | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build-and-push | |
steps: | |
- name: Setup SSH | |
uses: webfactory/[email protected] | |
with: | |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
- name: Install sshpass | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y sshpass | |
- name: Deploy Docker container on remote server | |
run: | | |
sshpass -p "${{ secrets.SERVER_PASSWORD }}" ssh -o StrictHostKeyChecking=no ${{ secrets.SERVER_USERNAME}}@${{ secrets.SERVER_IP }} << EOF | |
docker pull "${REGISTRY}/${DOCKER_IMAGE_NAME}:linux-latest" | |
docker stop $CONTAINER_NAME || true | |
docker container rm $CONTAINER_NAME || true | |
docker run -d --name $CONTAINER_NAME \ | |
--network eventhub \ | |
-p 5002:80 \ | |
-e ASPNETCORE_ENVIRONMENT=Development \ | |
-e ASPNETCORE_URLS=http://+:80 \ | |
"${REGISTRY}/${DOCKER_IMAGE_NAME}:linux-latest" | |
EOF |