Skip to content

Commit 66aeeb5

Browse files
authored
Merge pull request #4 from solvaholic/version2
Updates for v2.0.0
2 parents b89e659 + c9c38c8 commit 66aeeb5

12 files changed

Lines changed: 290 additions & 119 deletions

File tree

.config

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/sh
2+
3+
# Source this file from your script like:
4+
# . ./.config
5+
6+
# shellcheck disable=SC2034
7+
{
8+
9+
_image=solvaholic/octodns-sync:latest
10+
11+
_env_path=.env # .env file with secret keys and stuff
12+
_mountpoint=/config # Mountpoint for your config directory
13+
14+
# $_volume is the Docker will mount at $_mountpoint:
15+
if command -v wslpath >/dev/null 2>&1; then
16+
_volume="$(wslpath -a .)"
17+
else
18+
_volume="$(realpath .)"
19+
fi
20+
21+
}

.github/workflows/docker.yml

Lines changed: 83 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,36 @@ name: Docker
22

33
on:
44
push:
5+
# Only run when one of these files change.
6+
paths:
7+
- 'Dockerfile*'
8+
- entrypoint.sh
9+
- .github/workflows/docker.yml
10+
511
# Publish `master` as Docker `latest` image.
612
branches:
713
- master
8-
- solv1.1.0
9-
paths:
10-
- Dockerfile
11-
- entrypoint.sh
12-
- octodns-action.sh
13-
- touch
1414

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

19-
# Run tests for any PRs.
19+
# Run tests for any pull requests.
2020
pull_request:
2121
paths:
22-
- Dockerfile
22+
- 'Dockerfile*'
2323
- entrypoint.sh
24-
- octodns-action.sh
24+
- .github/workflows/docker.yml
25+
branches:
26+
- master
27+
tags:
28+
- v[12].[0-9]+.[0-9]+
2529

2630
env:
27-
IMAGE_NAME: octodns-action
31+
IMAGE_NAME: octodns-sync
2832

2933
jobs:
30-
# Run tests.
34+
# Prove the image successfully builds.
3135
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
3236
test:
3337
runs-on: ubuntu-latest
@@ -47,7 +51,7 @@ jobs:
4751
# Push image to GitHub's package registry and to Docker hub.
4852
# See also https://docs.docker.com/docker-hub/builds/
4953
push:
50-
# Ensure test job passes before pushing image.
54+
# Ensure test job passes before pushing images.
5155
needs: test
5256

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

6266
- name: Login to docker.pkg.github.com
63-
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
67+
run: |
68+
echo "${{ secrets.GITHUB_TOKEN }}" | \
69+
docker login docker.pkg.github.com \
70+
-u ${{ github.actor }} --password-stdin
6471
6572
- name: Push image to docker.pkg.github.com
6673
run: |
6774
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME
6875
69-
# Strip git ref prefix from version
70-
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
71-
72-
# Strip "v" prefix from tag name
73-
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
74-
75-
# Use Docker `latest` tag convention
76-
[ "$VERSION" == "master" ] && VERSION=latest
76+
# Build image tag strings to push to GitHub's package registry.
77+
_push_tags=""
78+
79+
# If GITHUB_REF is a branch, use the branch name.
80+
if [[ "${GITHUB_REF}" == "refs/heads/"* ]]; then
81+
VERSION=${GITHUB_REF#refs/heads/}
82+
# If branchname is mater, use the latest instead.
83+
[ "$VERSION" = "master" ] && VERSION=latest
84+
_push_tags+=\ $IMAGE_ID:$VERSION
85+
86+
# If GITHUB_REF looks like a version tag, use the tag name after
87+
# the leading v so vX.Y.Z becomes X.Y.Z.
88+
elif [[ "${GITHUB_REF}" == "refs/tags/v"* ]]; then
89+
VERSION=${GITHUB_REF#refs/tags/v}
90+
_push_tags+=\ $IMAGE_ID:$VERSION
91+
# If this looks like a semantic version tag, also tag the major.
92+
_push_tags+=\ $IMAGE_ID:${VERSION%%.*}
93+
94+
# If GITHUB_REF didn't match either of those rules, freak out.
95+
else
96+
echo "FAIL: Did not recognize GITHUB_REF '${GITHUB_REF}'."
97+
exit 1
98+
fi
7799
78100
echo IMAGE_ID=$IMAGE_ID
79101
echo VERSION=$VERSION
80102
81-
docker tag image $IMAGE_ID:$VERSION
82-
docker push $IMAGE_ID:$VERSION
103+
for _this_tag in ${_push_tags}; do
104+
echo "INFO: Tagging and pushing ${_this_tag}."
105+
docker tag image ${_this_tag}
106+
docker push ${_this_tag}
107+
done
83108
84109
- name: Login to Docker hub
85-
run: echo "${{ secrets.dockerhub_token }}" | docker login -u ${{ github.actor }} --password-stdin
110+
run: |
111+
echo "${{ secrets.dockerhub_token }}" | \
112+
docker login -u ${{ github.actor }} --password-stdin
86113
87114
- name: Push image to Docker hub
88115
run: |
89-
IMAGE_ID=solvaholic/$IMAGE_NAME
90-
91-
# Strip git ref prefix from version
92-
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
93-
94-
# Strip "v" prefix from tag name
95-
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
96-
97-
# Use Docker `latest` tag convention
98-
[ "$VERSION" == "master" ] && VERSION=latest
116+
IMAGE_ID=${{ github.actor }}/$IMAGE_NAME
117+
118+
# Build image tag strings to push to Docker hub.
119+
_push_tags=""
120+
121+
# If GITHUB_REF is a branch, use the branch name.
122+
if [[ "${GITHUB_REF}" == "refs/heads/"* ]]; then
123+
VERSION=${GITHUB_REF#refs/heads/}
124+
# If branchname is mater, use the latest instead.
125+
[ "$VERSION" = "master" ] && VERSION=latest
126+
_push_tags+=\ $IMAGE_ID:$VERSION
127+
128+
# If GITHUB_REF looks like a version tag, use the tag name after
129+
# the leading v so vX.Y.Z becomes X.Y.Z.
130+
elif [[ "${GITHUB_REF}" == "refs/tags/v"* ]]; then
131+
VERSION=${GITHUB_REF#refs/tags/v}
132+
_push_tags+=\ $IMAGE_ID:$VERSION
133+
# If this looks like a semantic version tag, also tag the major.
134+
_push_tags+=\ $IMAGE_ID:${VERSION%%.*}
135+
136+
# If GITHUB_REF didn't match either of those rules, freak out.
137+
else
138+
echo "FAIL: Did not recognize GITHUB_REF '${GITHUB_REF}'."
139+
exit 1
140+
fi
99141
100142
echo IMAGE_ID=$IMAGE_ID
101143
echo VERSION=$VERSION
102144
103-
docker tag image $IMAGE_ID:$VERSION
104-
docker push $IMAGE_ID:$VERSION
145+
for _this_tag in ${_push_tags}; do
146+
echo "INFO: Tagging and pushing ${_this_tag}."
147+
docker tag image ${_this_tag}
148+
docker push ${_this_tag}
149+
done

.github/workflows/housekeeping.yml

Lines changed: 0 additions & 36 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Perform release workflow tasks for this repo.
2+
3+
name: Release
4+
5+
on:
6+
release:
7+
types: [published]
8+
9+
# A workflow run is made up of 1+ jobs that can run sequentially or in parallel
10+
# Steps represent a sequence of tasks that will be executed as part of a job
11+
12+
jobs:
13+
# When a release is published, bump the corresponding short tag.
14+
# For example, when v2.0.4 is published, update v2 to v2.0.4's SHA.
15+
# TODO: Only run when tag_name matches /v[0-9]+\.[0-9]+\.[0-9]+/.
16+
# TODO: Only update when the published release is also the latest.
17+
bumptag:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Create/update the short tag to match the release tag
22+
env:
23+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24+
_repo: ${{ github.repository }}
25+
_api: https://api.github.com
26+
_tag_name: ${{ github.event.release.tag_name }}
27+
_tag_sha: ${{ github.sha }}
28+
run: |
29+
echo _tag_sha: ${_tag_sha}
30+
# Build the pieces of the curl command to use.
31+
_a="Authorization: token ${GITHUB_TOKEN}"
32+
_b="{\"ref\": \"refs/tags/${_tag_name%%.*}\","
33+
_b+=" \"sha\": \"${_tag_sha}\"}"
34+
_c="${_api}/repos/${_repo}/git/refs"
35+
# Create the short tag, if it doesn't exist yet.
36+
curl -sL -XPOST -H "${_a}" -d "${_b}" "${_c}"
37+
# Revise curl parts for a different call.
38+
_b="{\"sha\": \"${_tag_sha}\"}"
39+
_c="${_api}/repos/${_repo}/git/refs/tags/${_tag_name%%.*}"
40+
# Update the major version tag, for example "v2".
41+
curl -sL -XPATCH -H "${_a}" -d "${_b}" "${_c}"

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Run octodns with your config.
1+
# Run octodns-sync with your config.
22

33
FROM python:3-slim
44

README.md

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
# octodns-action
1+
# octodns-sync
22

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

5-
**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.
5+
octodns allows you to manage your DNS records in a portable format and publish changes across different DNS providers. It is extensible and customizable.
66

7-
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.
7+
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.
88

99
## Example workflow
1010

1111
```
12-
name: octodns
12+
name: octodns-sync
1313
1414
on:
1515
# Deploy config whenever DNS changes are pushed to master.
@@ -30,26 +30,17 @@ jobs:
3030
steps:
3131
- uses: actions/checkout@v2
3232
- name: Publish
33-
uses: solvaholic/octodns-action@v1
33+
uses: solvaholic/octodns-sync@v2
3434
with:
3535
config_path: public.yaml
3636
doit: --doit
3737
```
3838

39-
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`:
40-
41-
```
42-
- name: Publish
43-
uses: docker://solvaholic/octodns-action:v1
44-
with:
45-
args: public.yaml --doit
46-
```
47-
4839
## Inputs
4940

5041
### Secrets
5142

52-
(**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:
43+
(**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:
5344

5445
"route53-aws-key-id": "YOURIDGOESHERE"
5546
"route53-aws-secret-access-key": "YOURKEYGOESHERE"
@@ -66,7 +57,7 @@ env:
6657

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

69-
Default `"dns/public.yaml"`.
60+
Default `"public.yaml"`.
7061

7162
### `doit`
7263

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

7768
## Outputs
7869

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

81-
## Run locally
72+
```
73+
********************************************************************************
74+
* example.org.
75+
********************************************************************************
76+
* route53 (Route53Provider)
77+
* Update
78+
* <CnameRecord CNAME 3600, mail.example.org., before.example.org.> ->
79+
* <CnameRecord CNAME 3600, mail.example.org., after.example.org.> (config)
80+
* Create <ARecord A 3600, after.example.org., ['192.168.0.33']> (config)
81+
* Create <CaaRecord CAA 3600, after.example.org., ['0 issue "letsencrypt.org"']> (config)
82+
* Delete <ARecord A 3600, before.example.org., ['192.168.0.33']>
83+
* Delete <CaaRecord CAA 3600, before.example.org., ['0 issue "letsencrypt.org"']>
84+
* Update
85+
* <CnameRecord CNAME 3600, www.example.org., before.example.org.> ->
86+
* <CnameRecord CNAME 3600, www.example.org., after.example.org.> (config)
87+
* Summary: Creates=2, Updates=2, Deletes=2, Existing Records=8
88+
```
8289

83-
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.
90+
## Run locally
8491

8592
```
86-
_image=solvaholic/octodns-action:v1
87-
_config_path=dns/config/public.yaml # Path to your config, from inside the container
88-
_env_path=dns/.env # .env file with secret keys and stuff
89-
_volume="$(wslpath -a ./dns)" # Path Docker will mount at $_mountpoint
90-
_mountpoint=/config # Mountpoint for your config directory
93+
_image=solvaholic/octodns-sync:2
94+
_config_path=public.yaml # Path to config file in your repository
95+
_env_path=.env # .env file with secret keys and stuff
96+
_volume="$(realpath .)" # Path Docker will mount at $_mountpoint
97+
_mountpoint=/config # Mountpoint for your config directory
9198
9299
# Test changes:
93-
docker run --rm -v "${_volume}":${_mountpoint} --env-file ${_env_path} ${_image} ${_config_path}
100+
docker run --rm -v "${_volume}":${_mountpoint} \
101+
--env-file ${_env_path} ${_image} ${_mountpoint#/}/${_config_path}
94102
95103
# Really do it:
96-
docker run --rm -v "${_volume}":${_mountpoint} --env-file ${_env_path} ${_image} ${_config_path} --doit
104+
docker run --rm -v "${_volume}":${_mountpoint} \
105+
--env-file ${_env_path} ${_image} ${_mountpoint#/}/${_config_path} --doit
97106
```

0 commit comments

Comments
 (0)