Skip to content

fix docker build

fix docker build #137

Workflow file for this run

name: Docker
# This will run when:
# - when new code is pushed to master/main to push the tags latest.
# - when a pull request is created and updated to make sure the
# Dockerfile is still valid.
# To be able to push to dockerhub, this expects the following
# secrets to be set in the project:
# - DOCKERHUB_USERNAME : username that can push to the org
# - DOCKERHUB_PASSWORD : password asscoaited with the username
# To be able to push to github, this expects the following
# secrets to be set in the project:
# - GHCR_USERNAME : username that can push to the org
# - GHCR_PASSWORD : password asscoaited with the username
on:
push:
branches:
- master
- main
release:
types:
- published
pull_request:
# Certain actions will only run when this is the master/main repo.
env:
MAIN_REPO: EDmodel/ED2
DOCKERHUB_ORG: edmodel
jobs:
docker:
runs-on: ubuntu-20.04
permissions:
packages: write
strategy:
fail-fast: false
matrix:
include:
- name: gnu
PLATFORM: "linux/amd64,linux/arm64"
- name: intel
PLATFORM: "linux/amd64"
steps:
- uses: actions/checkout@v3
# disk cleanup
- name: Check disk space
run: df . -h
- name: Free disk space
run: |
sudo docker rmi $(docker image ls -aq) >/dev/null 2>&1 || true
sudo rm -rf \
/usr/share/dotnet /usr/local/lib/android /opt/ghc \
/usr/local/share/powershell /usr/share/swift /usr/local/.ghcup \
/usr/lib/jvm || true
echo "some directories deleted"
sudo apt install aptitude -y >/dev/null 2>&1
sudo aptitude purge aria2 ansible azure-cli shellcheck rpm xorriso zsync \
esl-erlang firefox gfortran-8 gfortran-9 google-chrome-stable \
google-cloud-sdk imagemagick \
libmagickcore-dev libmagickwand-dev libmagic-dev ant ant-optional kubectl \
mercurial apt-transport-https mono-complete libmysqlclient \
unixodbc-dev yarn chrpath libssl-dev libxft-dev \
libfreetype6 libfreetype6-dev libfontconfig1 libfontconfig1-dev \
snmp pollinate libpq-dev postgresql-client powershell ruby-full \
sphinxsearch subversion mongodb-org azure-cli microsoft-edge-stable \
-y -f >/dev/null 2>&1
sudo aptitude purge google-cloud-sdk -f -y >/dev/null 2>&1
sudo aptitude purge microsoft-edge-stable -f -y >/dev/null 2>&1 || true
sudo apt purge microsoft-edge-stable -f -y >/dev/null 2>&1 || true
sudo aptitude purge '~n ^mysql' -f -y >/dev/null 2>&1
sudo aptitude purge '~n ^php' -f -y >/dev/null 2>&1
sudo aptitude purge '~n ^dotnet' -f -y >/dev/null 2>&1
sudo apt-get autoremove -y >/dev/null 2>&1
sudo apt-get autoclean -y >/dev/null 2>&1
echo "some packages purged"
- name: Check disk space
run: |
sudo dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -nr | head
df . -h
sudo du /usr/ -hx -d 4 --threshold=1G | sort -hr | head
# calculate some variables that are used later
- name: version information
run: |
# find out what the BRANCH is, in case of a PR we will use the PR-<number>
if [ "${{ github.event.release.target_commitish }}" != "" ]; then
BRANCH="${{ github.event.release.target_commitish }}"
elif [[ $GITHUB_REF =~ pull ]]; then
BRANCH="$(echo $GITHUB_REF | sed 's#refs/pull/\([0-9]*\)/merge#PR-\1#')"
else
BRANCH=${GITHUB_REF##*/}
fi
# calculate the version and all tags
if [ "$BRANCH" == "main" -o "$BRANCH" == "master" ]; then
VERSION="latest"
tags="${{ matrix.name }}"
if [ "${{ matrix.name }}" == "intel" ]; then
tags="${tags} latest"
fi
else
VERSION="${{ matrix.name }}-$BRANCH"
tags="${{ matrix.name }}-$BRANCH"
fi
# should we push to dockerhub, and is there a README
DOCKERHUB_PUSH="false"
DOCKERHUB_README="false"
if [ "${{ github.repository }}" == "${{ env.MAIN_REPO }}" ]; then
if [ "${{ secrets.DOCKERHUB_USERNAME }}" != "" -a "${{ secrets.DOCKERHUB_PASSWORD }}" != "" ]; then
DOCKERHUB_PUSH="true"
if [ -e "README.md" ]; then
DOCKERHUB_README="true"
fi
fi
fi
# create a list of all images to be pushed
REPO="${{ github.repository_owner }}"
REPO="${REPO,,}"
IMAGE="${{ github.event.repository.name }}"
IMAGE="${IMAGE,,}"
DEV_IMAGES=""
IMAGES=""
for tag in ${tags}; do
if [ "$DOCKERHUB_PUSH" == "true" ]; then
DEV_IMAGES="${DEV_IMAGES}${{ env.DOCKERHUB_ORG }}/${IMAGE}-dev:${tag},"
IMAGES="${IMAGES}${{ env.DOCKERHUB_ORG }}/${IMAGE}:${tag},"
fi
DEV_IMAGES="${DEV_IMAGES}ghcr.io/${REPO}/${IMAGE}-dev:${tag},"
IMAGES="${IMAGES}ghcr.io/${REPO}/${IMAGE}:${tag},"
done
IMAGES="${IMAGES%,*}"
# save the results in env
echo "BRANCH=${BRANCH}"
echo "VERSION=${VERSION}"
echo "DOCKERHUB_README=${DOCKERHUB_README}"
echo "DOCKERHUB_PUSH=${DOCKERHUB_PUSH}"
echo "IMAGES=${IMAGES}"
echo "BRANCH=${BRANCH}" >> $GITHUB_ENV
echo "VERSION=${VERSION}" >> $GITHUB_ENV
echo "DOCKERHUB_README=${DOCKERHUB_README}" >> $GITHUB_ENV
echo "DOCKERHUB_PUSH=${DOCKERHUB_PUSH}" >> $GITHUB_ENV
echo "DEV_IMAGES=${DEV_IMAGES}" >> $GITHUB_ENV
echo "IMAGES=${IMAGES}" >> $GITHUB_ENV
- name: DF
run: df -h .
# setup docker build
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: DF
run: df -h .
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: DF
run: df -h .
- name: Inspect Builder
run: |
echo "Name: ${{ steps.buildx.outputs.name }}"
echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
echo "Status: ${{ steps.buildx.outputs.status }}"
echo "Flags: ${{ steps.buildx.outputs.flags }}"
echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
# login to registries
- name: Login to DockerHub
if: env.DOCKERHUB_PUSH == 'true'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: DF
run: df -h .
# build the dev docker images
- name: Build and push docker
uses: docker/build-push-action@v4
with:
push: true
platforms: ${{ matrix.PLATFORM }}
file: Dockerfile.${{ matrix.name }}
target: build
cache-from: type=gha,scope=ed-${{ matrix.name }}-build
cache-to: type=gha,scope=ed-${{ matrix.name }}-build,mode=max
tags: ${{ env.DEV_IMAGES }}
build-args: |
BRANCH: ${{ env.BRANCH }}
VERSION=${{ env.VERSION }}
BUILDNUMBER=${{ github.run_number }}
GITSHA1=${{ github.sha }}
# build the docker images
- name: Build and push docker
uses: docker/build-push-action@v4
with:
push: true
platforms: ${{ matrix.PLATFORM }}
file: Dockerfile.${{ matrix.name }}
cache-from: type=gha,scope=ed-${{ matrix.name }}-build
cache-to: type=gha,scope=ed-${{ matrix.name }}-build,mode=max
tags: ${{ env.IMAGES }}
build-args: |
BRANCH: ${{ env.BRANCH }}
VERSION=${{ env.VERSION }}
BUILDNUMBER=${{ github.run_number }}
GITSHA1=${{ github.sha }}
# this will update the README of the dockerhub repo
- name: Docker Hub Description
if: env.DOCKERHUB_README == 'true'
uses: peter-evans/dockerhub-description@v3
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
DOCKERHUB_REPOSITORY: ${{ env.DOCKERHUB_ORG }}/${{ github.event.repository.name }}
README_FILEPATH: README.md