Skip to content

Instantly share code, notes, and snippets.

@necolas
Last active January 1, 2016 21:09
Show Gist options
  • Select an option

  • Save necolas/8201662 to your computer and use it in GitHub Desktop.

Select an option

Save necolas/8201662 to your computer and use it in GitHub Desktop.

Revisions

  1. necolas revised this gist Jan 2, 2014. 2 changed files with 43 additions and 94 deletions.
    63 changes: 1 addition & 62 deletions Instructions.md
    Original file line number Diff line number Diff line change
    @@ -1,62 +1 @@
    # Ghetto git deployment strategy

    I wanted something simple for staging and deploying my static site.

    1. Generate build locally
    2. Push the build to a bare git repo on your server
    3. A `post-receive` hook checks out the files in the public directory

    ## Remote server config

    ssh into your server (has your public ssh key)

    ```
    ssh you@example.org
    ```

    create a directory for your site

    ```
    mkdir ~/example.com
    ```

    create a directory for git

    ```
    mkdir ~/example.git
    ```

    create a bare git repo

    ```
    cd example.git
    git init --bare
    ```

    setup a post-receive hook

    ```
    cat > hooks/post-receive
    #!/bin/sh
    GIT_WORK_TREE=/path/to/example.com git checkout -f
    chmod +x hooks/post-receive
    ```

    Repeat for staging server, if you want.

    ## Local process

    I'm using Make:

    Deploy to production

    ```
    make prod
    ```

    Deploy to staging

    ```
    make staging
    ```
    See: [A simple Git deployment strategt for static sites](http://nicolasgallagher.com/simple-git-deployment-strategy-for-static-sites/)
    74 changes: 42 additions & 32 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -1,34 +1,44 @@
    # Local project makefile

    BUILD_DIR := ./build
    DEPLOY_DIR := ./deploy
    STAGING_REPO = ssh://you@example.org/~/staging.example.git
    PROD_REPO = ssh://you@example.org/~/example.git

    build:
    # whatever your build step is

    clean-deploy:
    @ rm -rf $(DEPLOY_DIR)

    clone-prod: clean-deploy
    git clone $(PROD_REPO) $(DEPLOY_DIR)

    clone-staging: clean-deploy
    git clone $(STAGING_REPO) $(DEPLOY_DIR)

    # force update the remote repo with whatever is in the build directory
    STAGING_REPO = ssh://user@hostname/~/staging.example.git
    PROD_REPO = ssh://user@hostname/~/example.git

    install:
    npm install

    # Deploy tasks

    staging: build git-staging deploy
    @ git tag -f staging
    @ echo "Staging deploy complete"

    prod: build git-prod deploy
    @ git tag -f production
    @ echo "Production deploy complete"

    # Build tasks

    build: clean
    # whatever your build step is

    # Sub-tasks tasks

    clean:
    @ rm -rf $(BUILD_DIR)

    git-prod:
    @ cd $(BUILD_DIR) && \
    git init && \
    git remote add origin $(PROD_REPO)

    git-staging:
    @ cd $(BUILD_DIR) && \
    git init && \
    git remote add origin $(STAGING_REPO)

    deploy:
    cp -R $(BUILD_DIR)/ $(DEPLOY_DIR) && \
    cd $(DEPLOY_DIR) && \
    git checkout --orphan new_master && \
    git add -A && \
    git commit -m "Release" && \
    git branch -M master && \
    git push -f origin +master:refs/heads/master

    prod: build clone-prod deploy

    staging: build clone-staging deploy

    .PHONY: build clean-deploy clone-prod clone-staging deploy prod staging
    @ cd $(BUILD_DIR) && \
    git add -A && \
    git commit -m "Release" && \
    git push -f origin +master:refs/heads/master

    .PHONY: install build clean deploy git-prod git-staging prod staging
  2. necolas revised this gist Dec 31, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Instructions.md
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ I wanted something simple for staging and deploying my static site.

    ## Remote server config

    ssh into your server
    ssh into your server (has your public ssh key)

    ```
    ssh you@example.org
  3. necolas revised this gist Dec 31, 2013. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion Makefile
    Original file line number Diff line number Diff line change
    @@ -29,4 +29,6 @@ deploy:

    prod: build clone-prod deploy

    staging: build clone-staging deploy
    staging: build clone-staging deploy

    .PHONY: build clean-deploy clone-prod clone-staging deploy prod staging
  4. necolas revised this gist Dec 31, 2013. 1 changed file with 35 additions and 14 deletions.
    49 changes: 35 additions & 14 deletions Instructions.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # Simple git deployment strategy
    # Ghetto git deployment strategy

    I wanted something simple for staging and deploying my static site.

    @@ -8,34 +8,55 @@ I wanted something simple for staging and deploying my static site.

    ## Remote server config

    Repeat for staging server, if you want.
    ssh into your server

    ```
    # ssh into your server
    $ ssh you@example.org
    ssh you@example.org
    ```

    create a directory for your site

    # create a directory for your site
    $ mkdir ~/example.com
    ```
    mkdir ~/example.com
    ```

    # create a directory for git
    $ mkdir ~/example.git
    create a directory for git

    # create a bare git repo
    $ cd example.git
    $ git init --bare
    ```
    mkdir ~/example.git
    ```

    create a bare git repo

    ```
    cd example.git
    git init --bare
    ```

    # setup a post-receive hook
    $ cat > hooks/post-receive
    setup a post-receive hook

    ```
    cat > hooks/post-receive
    #!/bin/sh
    GIT_WORK_TREE=/path/to/example.com git checkout -f
    $ chmod +x hooks/post-receive
    chmod +x hooks/post-receive
    ```

    Repeat for staging server, if you want.

    ## Local process

    I'm using Make:

    Deploy to production

    ```
    make prod
    ```

    Deploy to staging

    ```
    make staging
    ```
  5. necolas revised this gist Dec 31, 2013. 2 changed files with 13 additions and 5 deletions.
    3 changes: 2 additions & 1 deletion Instructions.md
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ I wanted something simple for staging and deploying my static site.

    Repeat for staging server, if you want.

    ```console
    ```
    # ssh into your server
    $ ssh you@example.org
    @@ -37,4 +37,5 @@ I'm using Make:

    ```
    make prod
    make staging
    ```
    15 changes: 11 additions & 4 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -6,11 +6,16 @@ STAGING_REPO = ssh://you@example.org/~/staging.example.git
    PROD_REPO = ssh://you@example.org/~/example.git

    build:
    # whatever your build step is
    # whatever your build step is

    clean-deploy:
    @ rm -rf $(DEPLOY_DIR)

    clone-staging:
    @ rm -rf $(DEPLOY_DIR) && \
    git clone $(STAGING_REPO) $(DEPLOY_DIR)
    clone-prod: clean-deploy
    git clone $(PROD_REPO) $(DEPLOY_DIR)

    clone-staging: clean-deploy
    git clone $(STAGING_REPO) $(DEPLOY_DIR)

    # force update the remote repo with whatever is in the build directory
    deploy:
    @@ -22,4 +27,6 @@ deploy:
    git branch -M master && \
    git push -f origin +master:refs/heads/master

    prod: build clone-prod deploy

    staging: build clone-staging deploy
  6. necolas created this gist Dec 31, 2013.
    40 changes: 40 additions & 0 deletions Instructions.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    # Simple git deployment strategy

    I wanted something simple for staging and deploying my static site.

    1. Generate build locally
    2. Push the build to a bare git repo on your server
    3. A `post-receive` hook checks out the files in the public directory

    ## Remote server config

    Repeat for staging server, if you want.

    ```console
    # ssh into your server
    $ ssh you@example.org

    # create a directory for your site
    $ mkdir ~/example.com

    # create a directory for git
    $ mkdir ~/example.git

    # create a bare git repo
    $ cd example.git
    $ git init --bare

    # setup a post-receive hook
    $ cat > hooks/post-receive
    #!/bin/sh
    GIT_WORK_TREE=/path/to/example.com git checkout -f
    $ chmod +x hooks/post-receive
    ```

    ## Local process

    I'm using Make:

    ```
    make prod
    ```
    25 changes: 25 additions & 0 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    # Local project makefile

    BUILD_DIR := ./build
    DEPLOY_DIR := ./deploy
    STAGING_REPO = ssh://you@example.org/~/staging.example.git
    PROD_REPO = ssh://you@example.org/~/example.git

    build:
    # whatever your build step is

    clone-staging:
    @ rm -rf $(DEPLOY_DIR) && \
    git clone $(STAGING_REPO) $(DEPLOY_DIR)

    # force update the remote repo with whatever is in the build directory
    deploy:
    cp -R $(BUILD_DIR)/ $(DEPLOY_DIR) && \
    cd $(DEPLOY_DIR) && \
    git checkout --orphan new_master && \
    git add -A && \
    git commit -m "Release" && \
    git branch -M master && \
    git push -f origin +master:refs/heads/master

    staging: build clone-staging deploy