Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from DockerHub automation to GitHub Actions #13

Merged
merged 12 commits into from
Apr 17, 2021
16 changes: 16 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: 2
updates:

# Maintain dependencies for Docker
- package-ecosystem: docker
directory: "container/"
schedule:
interval: daily
open-pull-requests-limit: 10

# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
open-pull-requests-limit: 10
39 changes: 39 additions & 0 deletions .github/workflows/pullrequests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: ci

on:
pull_request:
types: [assigned, opened, synchronize, reopened]

jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Generate Build-Args
id: build-args
run: |
# echo ::set-output name=build-arg1::"buildarg1"
# echo ::set-output name=build-arg2::"buildarg2"
-
name: Hadolint
uses: brpaz/[email protected]
with:
dockerfile: container/Dockerfile
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
file: ./container/Dockerfile
platforms: linux/amd64,linux/arm/v7,linux/arm/v6,linux/arm64
tuxpeople marked this conversation as resolved.
Show resolved Hide resolved
push: false
103 changes: 103 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: ci

# This worflow needs this secret:
#
# DOCKERPASSWORD = Docker Hub token
tuxpeople marked this conversation as resolved.
Show resolved Hide resolved

on:
push:
branches: [master]
tags: 'v*.*.*'
ansemjo marked this conversation as resolved.
Show resolved Hide resolved
schedule:
- cron: "0 13 * * 1"

env:
PLATFORMS: "linux/amd64,linux/arm/v7,linux/arm/v6,linux/arm64, linux/ppc64le" # Build for which platforms
IMAGENAME: "ansemjo/speedtest" # Name of the image
DEFAULT_TAG: "latest" # Which tag is beeing used if we are building for master/main branch
DOCKER_USER: "ansemjo" # Which user to use to login to DockerHub
tuxpeople marked this conversation as resolved.
Show resolved Hide resolved

jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Generate Build-Args
id: build-args
run: |
# echo ::set-output name=build-arg1::"buildarg1"
# echo ::set-output name=build-arg2::"buildarg2"
-
name: Checkout
uses: actions/checkout@v2
-
name: Prepare
id: prep
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
if [[ $VERSION =~ ^v([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$ ]]; then
MAJOR="${BASH_REMATCH[1]}"
MINOR="${BASH_REMATCH[2]}"
PATCH="${BASH_REMATCH[3]}"

TAGS="${{ env.IMAGENAME }}:latest"
TAGS="${TAGS},${{ env.IMAGENAME }}:${MAJOR}"
TAGS="${TAGS},${{ env.IMAGENAME }}:${MAJOR}.${MINOR}"
TAGS="${TAGS},${{ env.IMAGENAME }}:${MAJOR}.${MINOR}.${PATCH}"
else
TAGS="${{ env.IMAGENAME }}:${VERSION}"
fi
elif [[ $GITHUB_REF == refs/heads/* ]]; then
ansemjo marked this conversation as resolved.
Show resolved Hide resolved
TAGS="${{ env.IMAGENAME }}:${{ env.DEFAULT_TAG }}"
elif [[ $GITHUB_REF == refs/pull/* ]]; then
TAGS="${{ env.IMAGENAME }}:pr-${{ github.event.number }}"
fi
echo ::set-output name=tags::${TAGS}
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
-
name: Hadolint
uses: brpaz/[email protected]
with:
dockerfile: container/Dockerfile
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ env.DOCKER_USER }}
password: ${{ secrets.DOCKERPASSWORD }}
-
name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
file: ./container/Dockerfile
platforms: ${{ env.PLATFORMS }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.prep.outputs.tags }}
build-args: |
${{ steps.build-args.outputs.build-arg1 }}
${{ steps.build-args.outputs.build-arg2 }}
labels: |
org.opencontainers.image.title=${{ github.event.repository.name }}
org.opencontainers.image.description=${{ github.event.repository.description }}
org.opencontainers.image.url=${{ github.event.repository.html_url }}
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }}
-
name: Docker Hub Description
uses: peter-evans/dockerhub-description@v2
with:
username: ${{ env.DOCKER_USER }}
password: ${{ secrets.DOCKERPASSWORD }}
repository: ${{ env.IMAGENAME }}

5 changes: 4 additions & 1 deletion container/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
# Licensed under the MIT License

# ---------- build taganaka/SpeedTest binary ----------
FROM alpine:latest as compiler
FROM alpine:3.13.4 as compiler

# install build framework and libraries
# hadolint ignore=DL3018
RUN apk add --no-cache alpine-sdk cmake curl-dev libxml2-dev

# configure and build binary
Expand All @@ -17,10 +18,12 @@ RUN git clone https://github.com/taganaka/SpeedTest.git . \
FROM python:3-alpine

# install necessary packages and fonts
# hadolint ignore=DL3018
RUN apk add --no-cache gnuplot ttf-droid libcurl libxml2 libstdc++ libgcc tini

# copy requirements file and install with pip
COPY requirements.txt /requirements.txt
# hadolint ignore=DL3018
RUN apk add --no-cache --virtual build-deps musl-dev gcc postgresql-dev \
&& apk add --no-cache postgresql-libs \
&& pip install --no-cache-dir -r /requirements.txt \
Expand Down