Skip to content

CI/CD Forklift

CI/CD Forklift #164

Workflow file for this run

name: CI/CD Forklift
on:
push:
schedule:
- cron: "38 11 */3 * *"
workflow_dispatch:
jobs:
build:
name: Build & test docker image
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Get last release version
id: lastrelease
uses: pozetroninc/github-action-get-latest-release@master
with:
repository: mtes-mct/fisheries-and-environment-data-warehouse
- name: Set ENV_PROFILE as PROD when it is a release
if: startsWith(github.ref, 'refs/tags/v0') || startsWith(github.ref, 'refs/heads/v0') || startsWith(github.ref, 'refs/tags/v1') || startsWith(github.ref, 'refs/heads/v1') || startsWith(github.ref, 'refs/tags/v2') || startsWith(github.ref, 'refs/heads/v2')
run: echo "ENV_PROFILE=prod" >> $GITHUB_ENV
- name: Set VERSION
run: |
if [ "${ENV_PROFILE}" != "prod" ]; then\
echo "VERSION=${{ steps.lastrelease.outputs.release }}_snapshot" >> $GITHUB_ENV
else\
echo "VERSION=${{ steps.lastrelease.outputs.release }}" >> $GITHUB_ENV
fi
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache-forklift
key: ${{ runner.os }}-single-buildx-forklift-${{ github.ref_name }}
restore-keys: |
${{ runner.os }}-single-buildx-forklift-
- name: Build image
uses: docker/build-push-action@v5
with:
context: .
load: true
builder: ${{ steps.buildx.outputs.name }}
file: infra/docker/Dockerfile.Forklift
push: false
tags: forklift:${{ env.VERSION }}
cache-from: type=local,src=/tmp/.buildx-cache-forklift
cache-to: type=local,dest=/tmp/.buildx-cache-forklift-new
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache-forklift
mv /tmp/.buildx-cache-forklift-new /tmp/.buildx-cache-forklift
- name: Set DOCKER_GROUP
run: echo "DOCKER_GROUP=$(getent group docker | cut --delimiter=":" -f3)" >> $GITHUB_ENV
- name: Test docker image
run: make docker-test-forklift
- name: Push docker image to registry
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v0') || startsWith(github.ref, 'refs/heads/v0') || startsWith(github.ref, 'refs/tags/v1') || startsWith(github.ref, 'refs/heads/v1') || startsWith(github.ref, 'refs/tags/v2') || startsWith(github.ref, 'refs/heads/v2')
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${GITHUB_ACTOR} --password-stdin
make docker-tag-forklift
make docker-push-forklift