Build docker image #444
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build docker image | |
on: | |
schedule: | |
- cron: '0 0 */3 * *' # @at 0h0m0s every 3 days | |
release: | |
types: [created] | |
push: | |
branches: [master] | |
jobs: | |
docker: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Fetch all history for all branches and tags | |
# | |
- name: Prepare | |
id: prep | |
run: | | |
if [[ $GITHUB_EVENT_NAME == schedule ]]; then | |
sudo apt-get update -y | |
sudo apt-get install -y curl jq | |
LATEST_TAG=$(curl -sSL https://api.github.com/repos/mdouchement/standardfile/releases/latest | jq -r .tag_name) | |
git checkout $LATEST_TAG | |
export GITHUB_REF=refs/tags/$LATEST_TAG | |
fi | |
# | |
# | |
# | |
DOCKER_IMAGE=mdouchement/standardfile | |
VERSION=edge | |
if [[ $GITHUB_REF == refs/heads/* ]]; then | |
# Branch name | |
VERSION=${GITHUB_REF#refs/heads/} | |
fi | |
if [[ $GITHUB_REF == refs/tags/v* ]]; then | |
# Tag name | |
VERSION=${GITHUB_REF#refs/tags/v} | |
fi | |
TAGS="${DOCKER_IMAGE}:${VERSION}" | |
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then | |
TAGS="$TAGS,${DOCKER_IMAGE}:latest" | |
fi | |
echo ::set-output name=tags::${TAGS} | |
# | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
# | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
# | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
# | |
- name: Build and push | |
id: docker_build | |
uses: docker/build-push-action@v5 | |
with: | |
file: Dockerfile | |
context: . | |
push: true | |
tags: ${{ steps.prep.outputs.tags }} |