Skip to content

Commit

Permalink
feat(docker): build separate alpine flavors
Browse files Browse the repository at this point in the history
ref: #3
  • Loading branch information
hertzg committed Jan 17, 2021
1 parent 7ef3f4b commit cc0f0ef
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 33 deletions.
44 changes: 16 additions & 28 deletions .github/workflows/buildx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
schedule:
- cron: 0 */12 * * *
push:
branches: [master]
branches: [ master ]
paths:
- ".github/workflows/buildx.yml"

Expand All @@ -13,38 +13,26 @@ jobs:
runs-on: ubuntu-latest
name: Buildx and push to dockerhub
steps:
- name: Set up Docker Buildx
id: buildx
uses: crazy-max/ghaction-docker-buildx@v1

- name: Cache Docker layers
uses: actions/cache@v2
id: cache
- uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Setup Node.js environment
uses: actions/setup-node@v2-beta
uses: actions/setup-node@v2
with:
node-version: 14

- name: Checkout
uses: actions/checkout@v2

- name: Login
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login --username ${{ secrets.DOCKER_USERNAME }} --password-stdin

- name: Build & Push
run: |
npm ci
node ./build.js \
--cache-from "type=local,src=/tmp/.buildx-cache" \
--cache-to "type=local,dest=/tmp/.buildx-cache"
- name: Clear
if: always()
run: |
rm -f ${HOME}/.docker/config.json
- uses: docker/setup-qemu-action@v1
- uses: docker/setup-buildx-action@v1
- uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- uses: actions/checkout@v2
- run: npm ci
- run: node ./build.js \
--cache-from "type=local,src=/tmp/.buildx-cache" \
--cache-to "type=local,dest=/tmp/.buildx-cache"
- if: always()
run: rm -f ${HOME}/.docker/config.json
17 changes: 12 additions & 5 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ const log = (first, ...args) =>
const {
IMAGE_BASENAME = "hertzg/rtl_433",
BUILD_PLATFORMS = "linux/amd64,linux/386,linux/arm64,linux/ppc64le,linux/arm/v7,linux/arm/v6",
ALPINE_VERSIONS = "3.13,3.12,3.11,3.10",
} = process.env;

const alpineVersions = ALPINE_VERSIONS.split(',')

const escape = (str) => str.replace('"', '\\"');

const variant = (tags, revision, alpine) => ({
Expand Down Expand Up @@ -70,16 +73,20 @@ fetch("https://api.github.com/repos/merbanan/rtl_433/tags")
.then((tags) => tags.map((tag) => tag.name))
.then(([latestGitTag, ...others]) => [
variant(["latest", latestGitTag], latestGitTag, "latest"),
//variant(["latest-edge", `${latestGitTag}-edge`], latestGitTag, "edge"),
variant(["master"], "master", "latest"),
//variant(["master-edge"], "master", "edge"),
...others.flatMap((gitTag) => [
variant([gitTag], gitTag, "latest"),
//variant([`${gitTag}-edge`], gitTag, "edge"),
variant([`${gitTag}`], gitTag, "latest"),
]),
...alpineVersions.flatMap((alpine) => [
variant([`alpine${alpine}-latest`, `alpine${alpine}-${latestGitTag}`], latestGitTag, alpine),
variant([`alpine${alpine}-master`], "master", alpine),
...others.flatMap((gitTag) => [
variant([`alpine${alpine}-${gitTag}`], gitTag, alpine),
]),
])
])
.then((variants) => {
log("Build all variants");
log("Build all variants", variants);
return buildParallel(variants, buildx);
})
.then(() => console.log("Done"))
Expand Down

0 comments on commit cc0f0ef

Please sign in to comment.