I am going to use Bitbucket as the source code repo; you can either use the CodeCommit, S3 bucket or GitHub. It’s all up to you. Make sure you have buildspec.yaml in your code. For the sake of simplicity, I will create a new hugo site so it will explain in a better way.

Setup CodeBuild with bitbucket private repo

  • Last Modified: 25 Sep, 2021

Make sure you have CodeBuild Project ready for the golang custom image.


Get Yours Today

Discover our wide range of products designed for IT professionals. From stylish t-shirts to cutting-edge tech gadgets, we've got you covered.

Explore Our Collection 🚀


Make sure you have CodeBuild Project ready for the golang custom image.

Please read my this article:

I am going to use Bitbucket as the source code repo; you can either use the CodeCommit, S3 bucket or GitHub. It’s all up to you. Make sure you have buildspec.yaml in your code. For the sake of simplicity, I will create a new hugo site so it will explain in a better way.

Prepare the basic Code

 hugo new site kayd
 cd kayd
 git init
 git submodule add https://github.com/theNewDynamic/gohugo-theme-ananke.git themes/ananke
 echo theme = \"ananke\" >> config.toml
 hugo new posts/my-first-post.md
  • If you do not have git installed, you can download the archive of the latest version of this theme from: github.com/theNewDynamic/gohugo-theme-ananke
  • Extract that .zip file to get a “gohugo-theme-ananke-master” directory.
  • Rename that directory to “ananke”, and move it into the “themes/” directory.

Publish the posts

Make sure your posts have draft:false otherwise they will not appear.

title: "My First Post"
date: 2019-03-26T08:47:11+01:00
draft: false

Add Deploy to the S3 in the config.toml

Make sure you have a s3 bucket where you want to deploy

baseURL = 'http://example.org/'
languageCode = 'en-us'
title: 'My New Hugo Site'
theme = "ananke"

[deployment]
[[deployment.targets]]
name = "s3"
URL = "s3://kayd-test-website"

Commit the code

Now we need to sync our code with the repo (S3, CodeCommit, etc…) I am using the S3 bucket, so I will use the sync command

  aws s3 sync . s3://kayd-code-bucket/

buildspec.yaml

version: 0.2

env:
  variables:
    hugo_version: "0.70.0"

phases:
  install:
    commands:
      - wget "https://github.com/gohugoio/hugo/releases/download/v${hugo_version}/hugo_${hugo_version}_Linux-64bit.deb"
      - dpkg -i hugo_${hugo_version}_Linux-64bit.deb
    finally:
      - hugo version
  pre_build:
    commands:
      - echo In pre_build phase..
      - echo Current directory is $CODEBUILD_SRC_DIR
      - ls -la
      - rm -rf public
    finally:
      - echo This always runs even if the login command fails 
  build:
    commands:
      - hugo -v
      - hugo deploy s3
    finally:
      - echo This always runs even if the install command fails
  post_build:
    commands:
      - echo Build completed on `date`

Create a private repo in bitbucket cloud

Create a CodeBuild Project

  • Choose the Source Provider as Bitbucket
  • Then you can connect to your repo via OAuth/Bitbucket app password
  • I chose OAuth and then grant access to my account
  • Choose your private repo from the list
  • Choose Webhook Rebuild every time a code change is pushed to this repository)

Once you start a build and successfully complete it, it will deploy to your target bucket. If you are having any trouble, then please send me a message. I will help you find the solution.

...
Get Yours Today

Discover our wide range of products designed for IT professionals. From stylish t-shirts to cutting-edge tech gadgets, we've got you covered.

Explore Our Collection 🚀


See Also

comments powered by Disqus