diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..08146fe --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,80 @@ +name: Docker Image CI + +on: + push: + branches: + - 'develop' + - 'main' + - 'master' + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + branches: + - 'develop' + - 'main' + - 'master' + workflow_dispatch: + inputs: + push_image: + description: 'Push the built image to DockerHub' + required: false + default: false + type: boolean + custom_tag: + description: "Optional extra tag (e.g. 'test-xyz'). Branch name is always tagged." + required: false + type: string + +jobs: + build: + runs-on: ubuntu-latest + # Skip draft PRs + if: github.event.pull_request.draft == false || github.event_name == 'push' + + steps: + - name: Check out the repo + uses: actions/checkout@v4 + + - name: Check if Dockerfile exists + id: check_dockerfile + run: | + if [ -f "src/sn-auth/Dockerfile" ]; then + echo "dockerfile_exists=true" >> $GITHUB_OUTPUT + else + echo "dockerfile_exists=false" >> $GITHUB_OUTPUT + echo "⚠️ No Dockerfile found, skipping Docker build" + fi + + - name: Set up Docker metadata + if: steps.check_dockerfile.outputs.dockerfile_exists == 'true' + id: meta + uses: docker/metadata-action@v5 + with: + images: sensenetcsp/sn-auth + tags: | + # Clean branch name (e.g., feature-conditional-recaptcha) + type=ref,event=branch + # 'latest' tag only when pushing to main or master (regardless of default branch) + type=raw,value=latest,enable=${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') }} + # 'preview' tag only when pushing to develop + type=raw,value=preview,enable=${{ github.event_name == 'push' && github.ref == 'refs/heads/develop' }} + # PR number for pull requests + type=ref,event=pr + # Optional custom tag from manual workflow_dispatch + type=raw,value=${{ inputs.custom_tag }},enable=${{ github.event_name == 'workflow_dispatch' && inputs.custom_tag != '' }} + + - name: Login to DockerHub + if: steps.check_dockerfile.outputs.dockerfile_exists == 'true' && (github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.push_image)) + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push Docker image + if: steps.check_dockerfile.outputs.dockerfile_exists == 'true' + uses: docker/build-push-action@v6 + with: + context: . + file: ./src/sn-auth/Dockerfile + push: ${{ github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.push_image) }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/src/sn-auth/Models/Options/EmailSettings.cs b/src/sn-auth/Models/Options/EmailSettings.cs index d18de2e..1d8231c 100644 --- a/src/sn-auth/Models/Options/EmailSettings.cs +++ b/src/sn-auth/Models/Options/EmailSettings.cs @@ -8,4 +8,5 @@ public class EmailSettings public string Password { get; set; } = string.Empty; public string FromEmail { get; set; } = string.Empty; public string FromName { get; set; } = string.Empty; + public bool EnableSsl { get; set; } = true; } diff --git a/src/sn-auth/Services/EmailService.cs b/src/sn-auth/Services/EmailService.cs index d772bec..d73c9e2 100644 --- a/src/sn-auth/Services/EmailService.cs +++ b/src/sn-auth/Services/EmailService.cs @@ -37,7 +37,7 @@ public void SendEmail(string toEmail, string subject, string emailBody) using var client = new SmtpClient(_emailSettings.Server, _emailSettings.Port); if (!string.IsNullOrEmpty(_emailSettings.Username) && !string.IsNullOrEmpty(_emailSettings.Password)) client.Credentials = new NetworkCredential(_emailSettings.Username, _emailSettings.Password); - client.EnableSsl = true; + client.EnableSsl = _emailSettings.EnableSsl; var mailMessage = new MailMessage { diff --git a/src/sn-auth/appsettings.json b/src/sn-auth/appsettings.json index 7bdefba..9cdc43a 100644 --- a/src/sn-auth/appsettings.json +++ b/src/sn-auth/appsettings.json @@ -27,7 +27,8 @@ "Server": "", "Port": 0, "FromEmail": "", - "FromName": "" + "FromName": "", + "EnableSsl": true }, "Registration": { "IsEnabled": false,