From 30d72f177086773c3b29034fc37ad6a70892a660 Mon Sep 17 00:00:00 2001 From: Nick Parker Date: Sat, 19 Jun 2021 22:21:00 +1200 Subject: [PATCH] Add CI and docker definitions --- .build.yml | 9 +++++++++ Dockerfile | 8 ++++++++ docker-build.sh | 18 ++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 .build.yml create mode 100644 Dockerfile create mode 100755 docker-build.sh diff --git a/.build.yml b/.build.yml new file mode 100644 index 0000000..73fc5f3 --- /dev/null +++ b/.build.yml @@ -0,0 +1,9 @@ +image: alpine/edge +packages: +- cargo +environment: + repo: twitch-rss +tasks: +- build: | + cd $repo/ + cargo test --all diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..34a6b81 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +# Builds an image containing the binary and little else. +FROM rust:slim +COPY . /twitch-rss +RUN cd /twitch-rss && cargo build --all-targets --release + +FROM debian:buster-slim +COPY --from=0 /twitch-rss/target/release/twitch-rss /twitch-rss +RUN chmod +x /twitch-rss diff --git a/docker-build.sh b/docker-build.sh new file mode 100755 index 0000000..056318b --- /dev/null +++ b/docker-build.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +set -euo pipefail +IFS=$'\n\t' + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +cd $SCRIPT_DIR + +PROJ_NAME=$(basename $SCRIPT_DIR) + +DOCKER_REGISTRY=${DOCKER_REGISTRY:=docker.io} +DOCKER_REPOSITORY=${DOCKER_REPOSITORY:="nickbp/${PROJ_NAME}:"} +DOCKER_BUILD=${DOCKER_BUILD:="docker buildx build --push --platform linux/amd64,linux/arm64"} + +# Get 7-character commit SHA (note: doesn't detect dirty commits) +COMMIT_SHA=$(git rev-parse HEAD | cut -b 1-7) + +time /bin/sh -c "$DOCKER_BUILD -t ${DOCKER_REGISTRY}/${DOCKER_REPOSITORY}${COMMIT_SHA} ." -- 2.45.2