Skip to content

Commit

Permalink
Merge pull request #4 from solvaholic/version2
Browse files Browse the repository at this point in the history
Updates for v2.0.0
  • Loading branch information
solvaholic authored Mar 26, 2020
2 parents b89e659 + c9c38c8 commit 66aeeb5
Show file tree
Hide file tree
Showing 12 changed files with 290 additions and 119 deletions.
21 changes: 21 additions & 0 deletions .config
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh

# Source this file from your script like:
# . ./.config

# shellcheck disable=SC2034
{

_image=solvaholic/octodns-sync:latest

_env_path=.env # .env file with secret keys and stuff
_mountpoint=/config # Mountpoint for your config directory

# $_volume is the Docker will mount at $_mountpoint:
if command -v wslpath >/dev/null 2>&1; then
_volume="$(wslpath -a .)"
else
_volume="$(realpath .)"
fi

}
121 changes: 83 additions & 38 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,36 @@ name: Docker

on:
push:
# Only run when one of these files change.
paths:
- 'Dockerfile*'
- entrypoint.sh
- .github/workflows/docker.yml

# Publish `master` as Docker `latest` image.
branches:
- master
- solv1.1.0
paths:
- Dockerfile
- entrypoint.sh
- octodns-action.sh
- touch

# Publish `v1.2.3` tags as releases.
# Publish `vX.Y.Z` tags as releases.
tags:
- v[0-9]+.[0-9]+.[0-9]+
- v[12]+.[0-9]+.[0-9]+

# Run tests for any PRs.
# Run tests for any pull requests.
pull_request:
paths:
- Dockerfile
- 'Dockerfile*'
- entrypoint.sh
- octodns-action.sh
- .github/workflows/docker.yml
branches:
- master
tags:
- v[12].[0-9]+.[0-9]+

env:
IMAGE_NAME: octodns-action
IMAGE_NAME: octodns-sync

jobs:
# Run tests.
# Prove the image successfully builds.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
test:
runs-on: ubuntu-latest
Expand All @@ -47,7 +51,7 @@ jobs:
# Push image to GitHub's package registry and to Docker hub.
# See also https://docs.docker.com/docker-hub/builds/
push:
# Ensure test job passes before pushing image.
# Ensure test job passes before pushing images.
needs: test

runs-on: ubuntu-latest
Expand All @@ -60,45 +64,86 @@ jobs:
run: docker build . --file Dockerfile --tag image

- name: Login to docker.pkg.github.com
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | \
docker login docker.pkg.github.com \
-u ${{ github.actor }} --password-stdin
- name: Push image to docker.pkg.github.com
run: |
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
# Build image tag strings to push to GitHub's package registry.
_push_tags=""
# If GITHUB_REF is a branch, use the branch name.
if [[ "${GITHUB_REF}" == "refs/heads/"* ]]; then
VERSION=${GITHUB_REF#refs/heads/}
# If branchname is mater, use the latest instead.
[ "$VERSION" = "master" ] && VERSION=latest
_push_tags+=\ $IMAGE_ID:$VERSION
# If GITHUB_REF looks like a version tag, use the tag name after
# the leading v so vX.Y.Z becomes X.Y.Z.
elif [[ "${GITHUB_REF}" == "refs/tags/v"* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
_push_tags+=\ $IMAGE_ID:$VERSION
# If this looks like a semantic version tag, also tag the major.
_push_tags+=\ $IMAGE_ID:${VERSION%%.*}
# If GITHUB_REF didn't match either of those rules, freak out.
else
echo "FAIL: Did not recognize GITHUB_REF '${GITHUB_REF}'."
exit 1
fi
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag image $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
for _this_tag in ${_push_tags}; do
echo "INFO: Tagging and pushing ${_this_tag}."
docker tag image ${_this_tag}
docker push ${_this_tag}
done
- name: Login to Docker hub
run: echo "${{ secrets.dockerhub_token }}" | docker login -u ${{ github.actor }} --password-stdin
run: |
echo "${{ secrets.dockerhub_token }}" | \
docker login -u ${{ github.actor }} --password-stdin
- name: Push image to Docker hub
run: |
IMAGE_ID=solvaholic/$IMAGE_NAME
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
IMAGE_ID=${{ github.actor }}/$IMAGE_NAME
# Build image tag strings to push to Docker hub.
_push_tags=""
# If GITHUB_REF is a branch, use the branch name.
if [[ "${GITHUB_REF}" == "refs/heads/"* ]]; then
VERSION=${GITHUB_REF#refs/heads/}
# If branchname is mater, use the latest instead.
[ "$VERSION" = "master" ] && VERSION=latest
_push_tags+=\ $IMAGE_ID:$VERSION
# If GITHUB_REF looks like a version tag, use the tag name after
# the leading v so vX.Y.Z becomes X.Y.Z.
elif [[ "${GITHUB_REF}" == "refs/tags/v"* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
_push_tags+=\ $IMAGE_ID:$VERSION
# If this looks like a semantic version tag, also tag the major.
_push_tags+=\ $IMAGE_ID:${VERSION%%.*}
# If GITHUB_REF didn't match either of those rules, freak out.
else
echo "FAIL: Did not recognize GITHUB_REF '${GITHUB_REF}'."
exit 1
fi
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag image $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
for _this_tag in ${_push_tags}; do
echo "INFO: Tagging and pushing ${_this_tag}."
docker tag image ${_this_tag}
docker push ${_this_tag}
done
36 changes: 0 additions & 36 deletions .github/workflows/housekeeping.yml

This file was deleted.

41 changes: 41 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Perform release workflow tasks for this repo.

name: Release

on:
release:
types: [published]

# A workflow run is made up of 1+ jobs that can run sequentially or in parallel
# Steps represent a sequence of tasks that will be executed as part of a job

jobs:
# When a release is published, bump the corresponding short tag.
# For example, when v2.0.4 is published, update v2 to v2.0.4's SHA.
# TODO: Only run when tag_name matches /v[0-9]+\.[0-9]+\.[0-9]+/.
# TODO: Only update when the published release is also the latest.
bumptag:
runs-on: ubuntu-latest

steps:
- name: Create/update the short tag to match the release tag
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
_repo: ${{ github.repository }}
_api: https://api.github.com
_tag_name: ${{ github.event.release.tag_name }}
_tag_sha: ${{ github.sha }}
run: |
echo _tag_sha: ${_tag_sha}
# Build the pieces of the curl command to use.
_a="Authorization: token ${GITHUB_TOKEN}"
_b="{\"ref\": \"refs/tags/${_tag_name%%.*}\","
_b+=" \"sha\": \"${_tag_sha}\"}"
_c="${_api}/repos/${_repo}/git/refs"
# Create the short tag, if it doesn't exist yet.
curl -sL -XPOST -H "${_a}" -d "${_b}" "${_c}"
# Revise curl parts for a different call.
_b="{\"sha\": \"${_tag_sha}\"}"
_c="${_api}/repos/${_repo}/git/refs/tags/${_tag_name%%.*}"
# Update the major version tag, for example "v2".
curl -sL -XPATCH -H "${_a}" -d "${_b}" "${_c}"
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Run octodns with your config.
# Run octodns-sync with your config.

FROM python:3-slim

Expand Down
63 changes: 36 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# octodns-action
# octodns-sync

This action runs [**github/octodns**](https://github.com/github/octodns) to deploy your DNS config to any cloud.
This action runs `octodns-sync` from [github/octodns](https://github.com/github/octodns) to deploy your DNS config to any cloud.

**octodns** allows you to manage your DNS records in a provider-agnostic format and test and publish changes with many different DNS providers. It is extensible and customizable.
octodns allows you to manage your DNS records in a portable format and publish changes across different DNS providers. It is extensible and customizable.

When you manage your **octodns** DNS configuration in a GitHub repository, this [GitHub Action](https://help.github.com/actions/getting-started-with-github-actions/about-github-actions) allows you to test and publish your changes automatically using a [workflow](https://help.github.com/actions/configuring-and-managing-workflows) you define.
When you manage your octodns DNS configuration in a GitHub repository, this [GitHub Action](https://help.github.com/actions/getting-started-with-github-actions/about-github-actions) allows you to test and publish your changes automatically using a [workflow](https://help.github.com/actions/configuring-and-managing-workflows) you define.

## Example workflow

```
name: octodns
name: octodns-sync
on:
# Deploy config whenever DNS changes are pushed to master.
Expand All @@ -30,26 +30,17 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Publish
uses: solvaholic/octodns-action@v1
uses: solvaholic/octodns-sync@v2
with:
config_path: public.yaml
doit: --doit
```

Please note running this action that way :point_up: will rebuild the Docker image on every run. This adds about 40 seconds to run time, and it uses more processing and I/O. To use [the image hosted on Docker hub](https://hub.docker.com/repository/docker/solvaholic/octodns-action) instead, pass the same `args` you would to `octodns-sync`:

```
- name: Publish
uses: docker://solvaholic/octodns-action:v1
with:
args: public.yaml --doit
```

## Inputs

### Secrets

(**Required**) To authenticate with your DNS provider, this action uses [encrypted secrets](https://help.github.com/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets#about-encrypted-secrets) you've configured on your repository. For example if you use Amazon Route53 then [create these secrets](https://help.github.com/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets#creating-encrypted-secrets) on the repository where you store your octodns config:
(**Required**) To authenticate with your DNS provider, this action uses [encrypted secrets](https://help.github.com/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets#about-encrypted-secrets) you've configured on your repository. For example, if you use Amazon Route53, [create these secrets](https://help.github.com/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets#creating-encrypted-secrets) on the repository where you store your DNS configuration:

"route53-aws-key-id": "YOURIDGOESHERE"
"route53-aws-secret-access-key": "YOURKEYGOESHERE"
Expand All @@ -66,7 +57,7 @@ env:

(**Required**) Path, relative to your repository root, of the config file you would like octodns to use.

Default `"dns/public.yaml"`.
Default `"public.yaml"`.

### `doit`

Expand All @@ -76,22 +67,40 @@ Default `""` (empty string).

## Outputs

--
`octodns-sync` will compare your configuration file to the configurations your providers have, and report any planned changes. For example:

## Run locally
```
********************************************************************************
* example.org.
********************************************************************************
* route53 (Route53Provider)
* Update
* <CnameRecord CNAME 3600, mail.example.org., before.example.org.> ->
* <CnameRecord CNAME 3600, mail.example.org., after.example.org.> (config)
* Create <ARecord A 3600, after.example.org., ['192.168.0.33']> (config)
* Create <CaaRecord CAA 3600, after.example.org., ['0 issue "letsencrypt.org"']> (config)
* Delete <ARecord A 3600, before.example.org., ['192.168.0.33']>
* Delete <CaaRecord CAA 3600, before.example.org., ['0 issue "letsencrypt.org"']>
* Update
* <CnameRecord CNAME 3600, www.example.org., before.example.org.> ->
* <CnameRecord CNAME 3600, www.example.org., after.example.org.> (config)
* Summary: Creates=2, Updates=2, Deletes=2, Existing Records=8
```

Notice this example uses `wslpath -a`. If you're not running this in Linux in WSL in Windows, you'll probably use `realpath` or so.
## Run locally

```
_image=solvaholic/octodns-action:v1
_config_path=dns/config/public.yaml # Path to your config, from inside the container
_env_path=dns/.env # .env file with secret keys and stuff
_volume="$(wslpath -a ./dns)" # Path Docker will mount at $_mountpoint
_mountpoint=/config # Mountpoint for your config directory
_image=solvaholic/octodns-sync:2
_config_path=public.yaml # Path to config file in your repository
_env_path=.env # .env file with secret keys and stuff
_volume="$(realpath .)" # Path Docker will mount at $_mountpoint
_mountpoint=/config # Mountpoint for your config directory
# Test changes:
docker run --rm -v "${_volume}":${_mountpoint} --env-file ${_env_path} ${_image} ${_config_path}
docker run --rm -v "${_volume}":${_mountpoint} \
--env-file ${_env_path} ${_image} ${_mountpoint#/}/${_config_path}
# Really do it:
docker run --rm -v "${_volume}":${_mountpoint} --env-file ${_env_path} ${_image} ${_config_path} --doit
docker run --rm -v "${_volume}":${_mountpoint} \
--env-file ${_env_path} ${_image} ${_mountpoint#/}/${_config_path} --doit
```
Loading

0 comments on commit 66aeeb5

Please sign in to comment.