Created
October 15, 2019 13:28
-
-
Save squizduos/21c626d6abbc9f75e120364d1289d8b8 to your computer and use it in GitHub Desktop.
Hugo in Docker image, packed with Alpine Lunux
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
FROM alpine:latest | |
# ARG PACKAGE="hugo_extended" | |
ARG PACKAGE="hugo" | |
ARG REPOSITORY="gohugoio/hugo" | |
ARG VERSION="0.58.2" | |
WORKDIR /opt | |
# Install dependencies (bash, curl and jq for parsing Github) | |
RUN apk update \ | |
&& apk add --no-cache --virtual build-dependencies curl \ | |
&& curl -O -L https://github.com/gohugoio/hugo/releases/download/v${VERSION}/${PACKAGE}_${VERSION}_Linux-64bit.tar.gz \ | |
&& tar -zxvf ${PACKAGE}_${VERSION}_Linux-64bit.tar.gz hugo \ | |
&& rm ${PACKAGE}_${VERSION}_Linux-64bit.tar.gz \ | |
&& ln -s /opt/hugo /usr/bin/hugo \ | |
&& apk del build-dependencies | |
CMD ["hugo"] |
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
#!/bin/bash | |
# Constants | |
REPOSITORY="gohugoio/hugo" | |
OS="Linux" | |
ARCH="32bit" | |
API_RELEASES_URL="https://api.github.com/repos/"${REPOSITORY}"/releases" | |
if [[ $VERSION == "latest" ]] | |
then | |
API_RELEASES_URL=$API_RELEASES_URL"/latest" ; | |
fi | |
echo "API Release URL: "$API_RELEASES_URL | |
PAGE_CONTENT=$(curl -s $API_RELEASES_URL) | |
if [[ $VERSION == "latest" ]] | |
then | |
JQ_SELECTOR_LATEST_TAG='.tag_name' | |
ACTUAL_VERSION=$(echo $PAGE_CONTENT | jq $JQ_SELECTOR_LATEST_TAG | tr -d '"v' ) | |
else | |
ACTUAL_VERSION=$(echo $VERSION | tr -d '"v') | |
fi | |
echo "Requested version is: "${ACTUAL_VERSION} | |
if [[ $OS == "Windows" ]] | |
then | |
EXT="zip" | |
else | |
EXT="tar.gz" | |
fi | |
ARCHIVE_NAME="hugo_"$ACTUAL_VERSION"_"$OS"-"$ARCH"."$EXT | |
echo "Archive name is: "${ARCHIVE_NAME} | |
if [[ $VERSION == "latest" ]] | |
then | |
JQ_SELECTOR_LATEST='.assets [] .browser_download_url | select(endswith("'$ARCHIVE_NAME'"))' | |
DOWNLOAD_LINK=$(echo $PAGE_CONTENT | jq -r "$JQ_SELECTOR_LATEST" | tr -d '"' ) | |
else | |
JQ_SELECTOR_ALL='.[] .assets [] .browser_download_url | select(endswith("'$ARCHIVE_NAME'"))' | |
DOWNLOAD_LINK=$(echo $PAGE_CONTENT | jq -r "$JQ_SELECTOR_ALL" | tr -d '"' ) | |
fi | |
echo "Downloading latest release from "$DOWNLOAD_LINK | |
cd /usr/local/hugo | |
curl -L $DOWNLOAD_LINK -o $ARCHIVE_NAME | |
tar xzf /usr/local/hugo/${ARCHIVE_NAME} -C /usr/local/hugo/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment