Migrate CI
All checks were successful
Build Docker image and publish / docker (push) Successful in 41s

This commit is contained in:
Ethanell 2024-02-17 00:03:25 +01:00
parent 72ad62398a
commit 0051463eea
2 changed files with 63 additions and 25 deletions

View file

@ -0,0 +1,63 @@
name: Build Docker image and publish
on: [push]
env:
DOCKER_REPOSITORY: "git.flifloo.fr"
jobs:
docker:
runs-on: docker
container:
image: docker:cli
env:
DOCKER_HOST: tcp://dind:2375
services:
dind:
image: docker:dind
cmd: [ "dockerd", "-H", "tcp://0.0.0.0:2375", "--tls=false" ]
steps:
- name: "Setup env"
id: env
run: |
echo "DOCKER_TAG=$DOCKER_REPOSITORY/$(echo "$GITHUB_REPOSITORY" | tr '[:upper:]' '[:lower:]'):latest" >> "$GITHUB_ENV"
apk add --no-cache git nodejs tar zstd
- name: "Get repo"
uses: actions/checkout@v4
- name: "Restore cache"
id: cache-restore
uses: actions/cache/restore@v4
with:
path: "${{ env.GITHUB_WORKSPACE }}/.docker_cache"
key: "docker"
- name: Set up Docker Buildx
uses: https://github.com/docker/setup-buildx-action@v3
- name: "Login to Docker repository"
uses: https://github.com/docker/login-action@v3
with:
registry: "${{ env.DOCKER_REPOSITORY }}"
username: "${{ env.GITHUB_ACTOR }}"
password: "${{ secrets.PACKAGE_TOKEN }}"
- name: "Build and push"
uses: https://github.com/docker/build-push-action@v5
with:
context: .
push: true
tags: "${{ env.DOCKER_TAG }}"
cache-from: "type=local,src=${{ env.GITHUB_WORKSPACE }}/.docker_cache"
cache-to: "type=local,dest=${{ env.GITHUB_WORKSPACE }}/.docker_cache"
- name: "Save cache"
id: cache-save
uses: actions/cache/save@v4
with:
path: "${{ env.GITHUB_WORKSPACE }}/.docker_cache"
key: "${{ steps.cache-restore.outputs.cache-primary-key }}"

View file

@ -1,25 +0,0 @@
docker-build:
image: docker:latest
stage: build
services:
- docker:dind
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
# Default branch leaves tag empty (= latest tag)
# All other branches are tagged with the escaped branch name (commit ref slug)
script:
- |
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
tag=""
echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 'latest'"
else
tag=":$CI_COMMIT_REF_SLUG"
echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag"
fi
- docker build --pull -t "$CI_REGISTRY_IMAGE${tag}" .
- docker push "$CI_REGISTRY_IMAGE${tag}"
# Run this job in a branch where a Dockerfile exists
rules:
- if: $CI_COMMIT_BRANCH
exists:
- Dockerfile