Skip to content

Commit

Permalink
Add CI/CD
Browse files Browse the repository at this point in the history
  • Loading branch information
xZero707 committed Sep 22, 2023
1 parent 9d5b841 commit cfbd8d7
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
version: 2
updates:

# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
assignees:
- "xZero707"

# Maintain Docker image dependencies
- package-ecosystem: "docker"
directory: "/"
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Build

on:
push:
branches:
- 'master'

jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
config-inline: |
[worker.oci]
max-parallelism = 16
-
name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
-
name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.PAT_TOKEN}}
-
name: Build and push
uses: docker/bake-action@v4.0.0
with:
files: build/docker-bake.hcl
push: true
14 changes: 11 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
ARG MARIADB_VERSION="10.11.5"
ARG MARIADB_SHORT_VERSION="10.11"
ARG MARIADB_VERSION="10.11"

FROM ghcr.io/n0rthernl1ghts/mariadb:${MARIADB_SHORT_VERSION} AS mariadb
FROM ghcr.io/n0rthernl1ghts/mariadb:${MARIADB_VERSION} AS mariadb
FROM mariadb AS mariadb-overlay

RUN set -eux \
Expand Down Expand Up @@ -47,4 +46,13 @@ ENV PS1="$(whoami)@$(hostname):$(pwd)\\$ " \
HOUSEKEEPER_PROCESS_LIMIT=10 \
CRONTAB_EXPRESSION="0 0 * * *"

ARG MARIADB_VERSION
LABEL maintainer="Aleksandar Puharic <aleksandar@puharic.com>" \
org.opencontainers.image.source="https://github.com/N0rthernL1ghts/mariadb-backup" \
org.opencontainers.image.description="MariaDB Backup Companion ${MARIADB_VERSION} (${TARGETPLATFORM})" \
org.opencontainers.image.licenses="MIT" \
org.opencontainers.image.version="${MARIADB_VERSION}"

ENV MARIADB_VERSION="${MARIADB_VERSION}"

ENTRYPOINT ["/init"]
93 changes: 93 additions & 0 deletions build/docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
group "default" {
targets = [
"10_6",
"10_11"
]
}

target "build-dockerfile" {
dockerfile = "Dockerfile"
}

target "build-platforms" {
platforms = ["linux/amd64", "linux/arm64"]
}

target "build-common" {
pull = true
}

######################
# Define the variables
######################

variable "REGISTRY_CACHE" {
default = "docker.io/nlss/mariadb-backup-cache"
}

######################
# Define the functions
######################

# Get the arguments for the build
function "get-args" {
params = [mariadb_version]
result = {
MARIADB_VERSION = mariadb_version
}
}

# Get the cache-from configuration
function "get-cache-from" {
params = [version]
result = [
"type=registry,ref=${REGISTRY_CACHE}:${sha1("${version}-${BAKE_LOCAL_PLATFORM}")}"
]
}

# Get the cache-to configuration
function "get-cache-to" {
params = [version]
result = [
"type=registry,mode=max,ref=${REGISTRY_CACHE}:${sha1("${version}-${BAKE_LOCAL_PLATFORM}")}"
]
}

# Get list of image tags and registries
# Takes a version and a list of extra versions to tag
# eg. get-tags("10.11.3", ["10.11.3-r0", "10.11", "latest"])
function "get-tags" {
params = [version, extra_versions]
result = concat(
[
"docker.io/nlss/mariadb-backup:${version}",
"ghcr.io/n0rthernl1ghts/mariadb-backup:${version}"
],
flatten([
for extra_version in extra_versions : [
"docker.io/nlss/mariadb-backup:${extra_version}",
"ghcr.io/n0rthernl1ghts/mariadb-backup:${extra_version}"
]
])
)
}

##########################
# Define the build targets
##########################

target "10_6" {
inherits = ["build-dockerfile", "build-platforms", "build-common"]
cache-from = get-cache-from("10.6.13")
cache-to = get-cache-to("10.6.13")
tags = get-tags("10.6", [])
args = get-args("10.6")
}

target "10_11" {
inherits = ["build-dockerfile", "build-platforms", "build-common"]
cache-from = get-cache-from("10.11.5")
cache-to = get-cache-to("10.11.5")
tags = get-tags("10.11", ["10", "latest"])
args = get-args("10.11")
}

0 comments on commit cfbd8d7

Please sign in to comment.