From 9111e2b1143251be3d1a05a268ed99f845e1a3e1 Mon Sep 17 00:00:00 2001 From: William McNulty Date: Thu, 31 Dec 2020 15:35:44 +0000 Subject: [PATCH 1/6] renamed github action workflow added terraform file to setup the domain name resource. added basic skeleton for the godaddy blog post --- .github/workflows/ci.yml | 74 +++++++++++++++++++++++++++++++++++ .github/workflows/node.js.yml | 30 -------------- infra/main.tf | 29 ++++++++++++++ posts/godaddy.md | 41 +++++++++++++++++++ 4 files changed, 144 insertions(+), 30 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/node.js.yml create mode 100644 infra/main.tf create mode 100644 posts/godaddy.md diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..2c68a28 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,74 @@ +# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions + +name: CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + + provision-dns: + + env: + GODADDY_API_KEY: ${{ secrets.GODADDY_API_KEY }} + GODADDY_API_SECRET: ${{ secrets.GODADDY_API_SECRET }} + + defaults: + run: + working-directory: infra # start in the infrastructure directory, rather than root + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - uses: hashicorp/setup-terraform@v1 + with: + cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} + + - run: bash <(curl -s https://raw.githubusercontent.com/n3integration/terraform-godaddy/master/install.sh) + + - name: Terraform fmt + id: fmt + run: terraform fmt -check + continue-on-error: true + + - name: Terraform Init + id: init + run: terraform init + + - name: Terraform Validate + id: validate + run: terraform validate -no-color + + - name: Terraform Plan + id: plan + run: terraform plan -no-color + continue-on-error: true + + - name: Terraform Apply + id: apply + run: terraform apply -no-color + + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [12.x] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - run: npm run build --if-present + - run: npm run export + - run: npm run deploy diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml deleted file mode 100644 index b65acde..0000000 --- a/.github/workflows/node.js.yml +++ /dev/null @@ -1,30 +0,0 @@ -# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions - -name: Node.js CI - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - build: - - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [12.x] - - steps: - - uses: actions/checkout@v2 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - run: npm install - - run: npm run build --if-present - - run: npm run export - - run: npm run deploy diff --git a/infra/main.tf b/infra/main.tf new file mode 100644 index 0000000..61b800c --- /dev/null +++ b/infra/main.tf @@ -0,0 +1,29 @@ +provider "godaddy" {} + + +resource "godaddy_domain_record" "gd-fancy-domain" { + domain = "mcnulty.xyz" + + // specify zero or more record blocks + // a record block allows you to configure A, or NS records with a custom time-to-live value + // a record block also allow you to configure AAAA, CNAME, TXT, or MX records + record { + name = "www" + type = "CNAME" + data = "mcnultyyy.github.io" + ttl = 3600 + } + + // specify any A records associated with the domain + // GitHub IPs as per https://docs.github.com/en/free-pro-team@latest/github/working-with-github-pages/managing-a-custom-domain-for-your-github-pages-site#configuring-an-apex-domain + addresses = [ + "185.199.108.153", + "185.199.109.153", + "185.199.110.153", + "185.199.111.153" + ] + + // specify any custom nameservers for your domain + // note: godaddy now requires that the 'custom' nameservers are first supplied through the ui + nameservers = ["ns75.domains.com", "ns76.domains.com"] +} \ No newline at end of file diff --git a/posts/godaddy.md b/posts/godaddy.md new file mode 100644 index 0000000..c220367 --- /dev/null +++ b/posts/godaddy.md @@ -0,0 +1,41 @@ +# Setting up a custom domain name using GitHub pages + +## Prerequisites + +- GitHub account +- GoDaddy account + domain +- Terraform account + +## Create GoDaddy API key + +The following environment variables/github secrets need to be setup + +Create a new API key from +https://developer.godaddy.com/keys/ + +Set the following repository secrets at https://github.com/McNultyyy/mcnultyyy.github.io/settings/secrets/actions +`GODADDY_API_KEY` +`GODADDY_API_SECRET` + +## Create the Terraform API key + +Create a new API key +https://app.terraform.io/app/mcnulty/settings/authentication-tokens + +And set it up a repository secret with the key as `TF_API_TOKEN` + +## Setting up the www domain + +Create a new file in the root of your github project called "CNAME" +The contents of this file should be the (sub)domain that you want to use (www.mcnulty.xyz) + +Create a DNS entry in your provider with the following mapping + +| Type | Name | Value | +| ----- | ---- | ------------------- | +| CNAME | www | mcnultyyy.github.io | + + +A quick note on DNS entries: +`A` entries map from a name to an IP +`CNAME` entries map from a name to another name From cb45b83e8743e4369f2bb24d0cf77b72a107b4e9 Mon Sep 17 00:00:00 2001 From: William McNulty Date: Thu, 31 Dec 2020 15:43:14 +0000 Subject: [PATCH 2/6] added step to add the godaddy provider to the local config file --- .github/workflows/ci.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2c68a28..96946b2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,7 +30,12 @@ jobs: with: cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} - - run: bash <(curl -s https://raw.githubusercontent.com/n3integration/terraform-godaddy/master/install.sh) + - run: | + bash <(curl -s https://raw.githubusercontent.com/n3integration/terraform-godaddy/master/install.sh) + cat > ~/.terraformrc < Date: Thu, 31 Dec 2020 15:56:04 +0000 Subject: [PATCH 3/6] syntax fix for eof --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 96946b2..4c22059 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,6 +36,7 @@ jobs: providers { godaddy = "$HOME/.terraform/plugins/terraform-godaddy" } + EOF - name: Terraform fmt id: fmt From 1e69d45d2b8b349c8cf914f207d5e195df3363bc Mon Sep 17 00:00:00 2001 From: William McNulty Date: Thu, 31 Dec 2020 16:00:35 +0000 Subject: [PATCH 4/6] . --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4c22059..4adc5e6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,6 +37,7 @@ jobs: godaddy = "$HOME/.terraform/plugins/terraform-godaddy" } EOF + ls -la - name: Terraform fmt id: fmt From 34395d400eab0356aaf188a18008a0b57842e9f1 Mon Sep 17 00:00:00 2001 From: McNultyyy Date: Sat, 2 Jan 2021 13:56:54 +0000 Subject: [PATCH 5/6] setup git user details in ci --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4adc5e6..3a4f578 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,6 +25,8 @@ jobs: steps: - uses: actions/checkout@v2 + + - uses: fregante/setup-git-user@v1 # sets the user.name and user.email gitconfig - uses: hashicorp/setup-terraform@v1 with: From 94376d0a957843260583c577d2956008aead90f4 Mon Sep 17 00:00:00 2001 From: William McNulty Date: Sun, 7 Mar 2021 21:25:39 +0000 Subject: [PATCH 6/6] update --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4adc5e6..f084a48 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,6 +63,8 @@ jobs: build: + needs: [provision-dns] + runs-on: ubuntu-latest strategy: