Skip to content

Instantly share code, notes, and snippets.

@peter-dolkens
Last active February 17, 2020 03:05
Show Gist options
  • Select an option

  • Save peter-dolkens/4b89c5a732ef1ea4fcb714252037e4ba to your computer and use it in GitHub Desktop.

Select an option

Save peter-dolkens/4b89c5a732ef1ea4fcb714252037e4ba to your computer and use it in GitHub Desktop.

Revisions

  1. peter-dolkens revised this gist Feb 17, 2020. No changes.
  2. peter-dolkens revised this gist Feb 17, 2020. 1 changed file with 20 additions and 35 deletions.
    55 changes: 20 additions & 35 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -2,12 +2,6 @@ SHELL := /usr/bin/env bash

    .PHONY : all

    SECRETS_ENV_FILE=environment_variables/secrets//.env
    GLOBAL_ENV_FILE=environment_variables/global//.env

    include ${SECRETS_ENV_FILE}
    include ${GLOBAL_ENV_FILE}

    ###############################################################################
    # HELP
    ###############################################################################
    @@ -36,39 +30,30 @@ help:
    } \
    { lastLine = $$0 }' $(MAKEFILE_LIST)

    ## Make local docker image for deployment
    image:
    docker build --build-arg WORKING_DIR=${WORKING_DIR} \
    -t ${DEPLOY_IMAGE_NAME} .

    ## Step into local image for debugging
    ## Debug the Jeckyll build
    debug:
    MSYS_NO_PATHCONV=1 \
    MSYS2_ARG_CONV_EXC="*" \
    docker run -it --env-file ${SECRETS_ENV_FILE} \
    --env-file ${GLOBAL_ENV_FILE} \
    --env ACTION=debug \
    -v data:/data/teamcity_server/datadir \
    -v logs:/opt/teamcity/logs \
    -v $(shell pwd):${WORKING_DIR} \
    --rm ${DEPLOY_IMAGE_NAME} \
    bash
    docker run -it \
    -v $(shell pwd)/src:/srv/jekyll \
    --rm jekyll/builder:3.8 \
    bash

    ## Launch TeamCity on port 8080
    launch:
    ## Build the Jeckyll site
    build:
    MSYS_NO_PATHCONV=1 \
    MSYS2_ARG_CONV_EXC="*" \
    docker run -it --name teamcity-linux-server \
    --env-file ${SECRETS_ENV_FILE} \
    --env-file ${GLOBAL_ENV_FILE} \
    -v data:/data/teamcity_server/datadir \
    -v logs:/opt/teamcity/logs \
    -p ${SERVER_PORT}:8111 \
    ${DEPLOY_IMAGE_NAME}
    docker run \
    -v $(shell pwd)/src:/srv/jekyll \
    --rm jekyll/builder:3.8 \
    /bin/bash -c "chmod 777 /srv/jekyll && jekyll build"

    ## Cleanup TeamCity volumes and containers
    cleanup:
    -docker stop teamcity-linux-server
    -docker rm teamcity-linux-server
    -docker volume rm logs
    -docker volume rm data
    ## Run the Jeckyll site
    run:
    MSYS_NO_PATHCONV=1 \
    MSYS2_ARG_CONV_EXC="*" \
    docker run -it -p 4000:4000 \
    -v $(shell pwd)/src:/srv/jekyll \
    --env JEKYLL_ENV=production \
    --rm jekyll/jekyll:3.8 \
    jekyll serve --watch --config _config.yml
  3. peter-dolkens created this gist Feb 17, 2020.
    74 changes: 74 additions & 0 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,74 @@
    SHELL := /usr/bin/env bash

    .PHONY : all

    SECRETS_ENV_FILE=environment_variables/secrets//.env
    GLOBAL_ENV_FILE=environment_variables/global//.env

    include ${SECRETS_ENV_FILE}
    include ${GLOBAL_ENV_FILE}

    ###############################################################################
    # HELP
    ###############################################################################

    # COLORS
    GREEN := $(shell tput -Txterm setaf 2)
    YELLOW := $(shell tput -Txterm setaf 3)
    WHITE := $(shell tput -Txterm setaf 7)
    RESET := $(shell tput -Txterm sgr0)

    TARGET_MAX_CHAR_NUM=20
    ## Show help
    help:
    @echo ''
    @echo 'Usage:'
    @echo ' make ${YELLOW}<target>${RESET} ${GREEN}<description>${RESET}'
    @echo ''
    @echo 'Targets:'
    @awk '/^[a-zA-Z\-_0-9]+:/ { \
    helpMessage = match(lastLine, /^## (.*)/); \
    if (helpMessage) { \
    helpCommand = substr($$1, 0, index($$1, ":")); \
    helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
    printf " ${YELLOW}%-$(TARGET_MAX_CHAR_NUM)s${RESET} ${GREEN}%s${RESET}\n", helpCommand, helpMessage; \
    } \
    } \
    { lastLine = $$0 }' $(MAKEFILE_LIST)

    ## Make local docker image for deployment
    image:
    docker build --build-arg WORKING_DIR=${WORKING_DIR} \
    -t ${DEPLOY_IMAGE_NAME} .

    ## Step into local image for debugging
    debug:
    MSYS_NO_PATHCONV=1 \
    MSYS2_ARG_CONV_EXC="*" \
    docker run -it --env-file ${SECRETS_ENV_FILE} \
    --env-file ${GLOBAL_ENV_FILE} \
    --env ACTION=debug \
    -v data:/data/teamcity_server/datadir \
    -v logs:/opt/teamcity/logs \
    -v $(shell pwd):${WORKING_DIR} \
    --rm ${DEPLOY_IMAGE_NAME} \
    bash

    ## Launch TeamCity on port 8080
    launch:
    MSYS_NO_PATHCONV=1 \
    MSYS2_ARG_CONV_EXC="*" \
    docker run -it --name teamcity-linux-server \
    --env-file ${SECRETS_ENV_FILE} \
    --env-file ${GLOBAL_ENV_FILE} \
    -v data:/data/teamcity_server/datadir \
    -v logs:/opt/teamcity/logs \
    -p ${SERVER_PORT}:8111 \
    ${DEPLOY_IMAGE_NAME}

    ## Cleanup TeamCity volumes and containers
    cleanup:
    -docker stop teamcity-linux-server
    -docker rm teamcity-linux-server
    -docker volume rm logs
    -docker volume rm data