Proof (continuous function on compact set attains its bounds)
$f$ is bounded
The image $f(X)\subseteq \R$ is compact and is therefore (totally) bounded.
$f$ attains its bounds
(This is showing a compact subset of $\R$ attains its bounds.)
Let $Y = f(X)$. Suppose $\sup Y\not\in Y$.
Consider the open cover of $Y$ $$ \begin{align*} \mathcal{U} = \sb{(-\infty, y)}{y\in Y}. \end{align*} $$
Since $Y$ is compact, there exists a finite subcover, so for some $y_1, \ldots, y_N\in Y$, $$ \begin{align*} Y\subseteq \bigcup_{1\leq i\leq N} (-\infty, y_i). \end{align*} $$
But then $$ \begin{align*} \sup Y \leq \sup \bigcup_{1\leq i\leq N} (-\infty, y_i) = \max_{1\leq i\leq N} y_i \in Y \end{align*} $$ which contradicts with the definition of $\sup Y$.