Skip to content
This repository has been archived by the owner on Jun 8, 2024. It is now read-only.

Commit

Permalink
Add container
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSilkky committed Jul 21, 2023
1 parent 5f12119 commit 19668ca
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
96 changes: 96 additions & 0 deletions .github/workflows/docker-build-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Docker Build & Push

on:
push:
paths-ignore:
- "**.md"
- "docker-compose.yml"
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:

env:
restic_version: "0.15.2"

jobs:
restic:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true

- name: Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: |
ghcr.io/thesilkky/restic
thesilkky/restic
tags: |
type=schedule,pattern={{date 'YYYYMMDD'}}
type=ref,event=branch
type=ref,event=pr
type=sha
type=sha,format=long
type=semver,pattern={{version}},value=v${{ env.restic_version }}
flavor: |
latest=true
- name: Setup QEMU
uses: docker/setup-qemu-action@v2

- name: Setup Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
with:
version: latest

- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Cache Docker layers
if: github.event_name != 'pull_request'
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: cinny-${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
cinny-${{ runner.os }}-buildx-
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
build-args: RESTIC_VERSION=${{ env.restic_version }}
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new

# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move Cache
if: github.event_name != 'pull_request'
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
48 changes: 48 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#syntax=docker/dockerfile:1-labs

ARG GO_VERSION=1.20.6
ARG ALPINE_VERSION=3.18
ARG RESTIC_VERSION

####################################################################################################
## Builder
####################################################################################################
FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS builder

ARG TARGETOS
ARG TARGETARCH

ENV CGO_ENABLE=0

RUN apk add --no-cache \
ca-certificates \
git

ADD --keep-git-dir=true https://github.com/restic/restic.git#v${RESTIC_VERSION} /restic

WORKDIR /restic

RUN go run helpers/build-release-binaries/main.go --platform "${TARGETOS}/${TARGETARCH}" --skip-compress && \
mv "/output/restic_${TARGETOS}_${TARGETARCH}" /output/restic

####################################################################################################
## Final image
####################################################################################################
FROM alpine:${ALPINE_VERSION}

RUN apk add --no-cache \
ca-certificates \
tzdata \
bash

COPY --from=builder --chmod=755 /output/restic /usr/local/bin
COPY --chmod=755 entrypoint.sh /

ENTRYPOINT ["/entrypoint.sh"]

CMD ["restic", "--help"]

LABEL org.opencontainers.image.source="https://github.com/restic/restic.git"
LABEL org.opencontainers.image.licenses="BSD-2-Clause"
LABEL org.opencontainers.image.title="Restic"
LABEL org.opencontainers.image.description="Fast, secure, efficient backup program"
9 changes: 9 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

if [[ -f $INIT_SCRIPT ]]; then
echo "Running init script: ${INIT_SCRIPT}"
source "$INIT_SCRIPT"
fi

echo "Running Restic: $(date)"
exec "$@"

0 comments on commit 19668ca

Please sign in to comment.