Skip to content

An open source, self-hosted, real-time port monitoring and discovery tool.

feat: add GitHub Actions workflow for building and publishing Docker image

Mostafa Wahiedd3a99d7c27bc
diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml
new file mode 100644
index 0000000..63f3bcf
--- /dev/null
+++ b/.github/workflows/docker-publish.yml
@@ -0,0 +1,71 @@
+name: Build and Publish Docker Image
+
+on:
+ push:
+ branches: [ "main" ]
+ tags: [ "v*.*.*" ]
+ pull_request:
+ branches: [ "main" ]
+
+env:
+ IMAGE_NAME: portracker
+
+jobs:
+ build-and-push:
+ runs-on: ubuntu-latest
+ permissions:
+ contents: read
+ packages: write
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v4
+
+ - name: Set up Docker Buildx
+ uses: docker/setup-buildx-action@v3
+
+ - name: Log in to Docker Hub
+ if: github.event_name != 'pull_request'
+ uses: docker/login-action@v3
+ with:
+ username: ${{ secrets.DOCKERHUB_USERNAME }}
+ password: ${{ secrets.DOCKERHUB_TOKEN }}
+
+ - name: Extract metadata (tags, labels) for Docker
+ id: meta
+ uses: docker/metadata-action@v5
+ with:
+ images: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}
+ tags: |
+ type=ref,event=branch
+ type=ref,event=pr
+ type=semver,pattern={{version}}
+ type=semver,pattern={{major}}.{{minor}}
+ type=raw,value=latest,enable={{is_default_branch}}
+
+ - name: Build and push Docker image
+ uses: docker/build-push-action@v5
+ with:
+ context: .
+ file: ./Dockerfile
+ push: ${{ github.event_name != 'pull_request' }}
+ tags: ${{ steps.meta.outputs.tags }}
+ labels: ${{ steps.meta.outputs.labels }}
+ cache-from: type=gha
+ cache-to: type=gha,mode=max
+ platforms: linux/amd64,linux/arm64
+
+ - name: Test Docker image
+ if: github.event_name != 'pull_request'
+ run: |
+ docker run --rm -d --name test-portracker \
+ -e PORT=3000 \
+ -e DATABASE_PATH=/data/test.db \
+ ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:latest
+
+ sleep 10
+
+ # Test if the application is responding
+ docker exec test-portracker wget --no-verbose --tries=1 --spider http://localhost:3000/api/servers || exit 1
+
+ docker stop test-portracker