Giter VIP home page Giter VIP logo

aws-s3's Introduction

aws-s3

A continuous delivery pipeline for a Hugo-based website in an S3 bucket.

Steps to create:

  1. In a Cloud9 environment, download and uncompress the latest Hogo "extended" release:
wget https://github.com/gohugoio/hugo/releases/download/\
v0.85.0/hugo_extended_0.85.0_Linux-64bit.tar.gz
tar zxvf hugo_extended_0.85.0_Linux-64bit.tar.gz
  1. Move hugo file into a bin directory:
mkdir -p ~/bin
mv hugo ~/bin
which hugo
  1. Create a GitHub repository, and include a .gitignore file with public added.

  2. Clone the repo into the same Cloud9 environment, and cd into it:

git clone <GitHub repo>
cd <repo directory>
  1. Create a local website in hugo:
hugo new site quickstart
  1. Move quickstart contents to root of repo directory, and then remove quickstart folder:
mv quickstart/* .
rmdir quickstart
  1. Add a theme:
git submodule add https://github.com/budparr/gohugo-theme-ananke.git themes/ananke
echo 'theme = "ananke"' >> config.toml
  1. Create a post, which can be edited in Markdown at content/posts/my-first-post:
hugo new posts/my-first-post.md

  1. In the Markdown file, under content/posts, toggle "draft: true" to "draft: false" to publish post.

  2. To run Hugo as a development server, open a TCP port:

    • Go to your EC2 instances, and click on the title that starts with aws-cloud9 and is in a running state
    • Click on the "Security" tab, then "Security groups" link, then "Edit inbound rules" button, then "Add rule" button
    • Set the "Port range" to 8080 and the "Source" to 0.0.0.0/0 and then click the "Save rules" button
    • Navigate back to the Cloud9 console and run curl ipinfo.io to get the testing IP address
    • Run hugo serve --bind=0.0.0.0 --port=8080 --baseURL=http://<IP address>/
  3. To run the website serverless, first create an S3 bucket:

    • Go to your S3 buckets, and create a new bucket
    • Open bucket, go to the "Properties" tab, click on "Edit" for "Static website hosting", and click on "Enable"
    • Specify "index.html" and "error.html" as the "Index" and "Error" docments, and then hit "Save changes"
    • Go to "Permissions" tab, click "Edit" for "Block public access", uncheck "Block all public access", hit "Save changes"
    • Then click "Edit" for "Bucket policy", and add a policy like the code shown below (but with your Bucket ARN, shown on top of edit area, and make sure it ends with /*), and hit "Save changes":
{
  "Version":"2012-10-17",
  "Statement":[
	{
	  "Sid":"PublicRead",
	  "Effect":"Allow",
	  "Principal": "*",
	  "Action":["s3:GetObject","s3:GetObjectVersion"],
	  "Resource":["arn:aws:s3:::DOC-EXAMPLE-BUCKET/*"]
	}
  ]
}
  1. In the Cloud9 console, run hugo to generate html, then copy public file to just created bucket (using bucket name, not the ARN), in correct region:
aws s3 sync public/ s3://<bucket-name> --region <for example, us-east-2> --delete
  1. View the website using the URL in the bucket's Properties > Static website hosting information.

  2. To set up continous delivery, create a CodeBuild project:

    • Go to CodeBuild and create a new project in the same region as your S3 bucket
    • In "Source", set provider to "GitHub", and select "Repository in my GitHub account"
    • Also in "Source", add "GitHub repository", and optionally add "Source version"
    • Under "Additional configuration", check "Use Git submodules" so that the theme can be pulled in
    • In "Primary source webhook events", select "Rebuild every time a code change is pushed to this repository"
    • In "Environment", for the "Operating system" select "Amazon Linux 2", and for "Runtime(s)" select "Standard"
    • Also in "Environment", for "Image" select "aws/codebuild/amazonlinux2-x86_64-standard:2.0"
    • Also in "Environment", under "Privileged", click to enable flag to build Docker images
    • Also in "Environment", select whether "Service role" will be a new or existing role, and fill in "Role name"
    • Click "Create build project"
    • Whatever the service role is, make sure there is an "AdministratorAccess" policy attached to it under IAM roles
  3. Create buildspec.yml file:

touch buildspec.yml 
  1. Add text to buildspec.yml like that in this repository, but edit:

    • Under environment_variables, HUGO_VERSION - to match Hugo version you're using
    • Under post_build, aws s3 sync - to match bucket and region
  2. Add, commit and push files in repo to GitHub:

git add *
git commit -m "Add Hugo files"
git push

Video tutorials

More references

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.