Let w be the vector of weights and S be the comformable matrix of covariances. The portfolio variance is given by w’Sw. So just minimize that with whatever constraints you want. If you just asssume weights sum to one, it is a classic quadratic optimization with linear equality constraints. Well known solutions.