Build #20
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 | |
on: | |
push: | |
paths: | |
- '.github/workflows/build.yml' | |
schedule: | |
- cron: '0 0 * * *' # every day in 00:00 | |
workflow_dispatch: | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
vars: | |
name: Generation vars | |
runs-on: ubuntu-latest | |
outputs: | |
prefix-latest: ${{ steps.basic.outputs.last_tag }} | |
steps: | |
- name: Get version | |
id: _tmp_last_tag | |
env: | |
DOCKERHUB_IMAGE: ${{ vars.BASE_IMAGE }} | |
run: | | |
version=$(curl -L --fail "https://hub.docker.com/v2/repositories/${{ env.DOCKERHUB_IMAGE }}/tags/?page_size=1000" | \ | |
jq '.results | .[] | .name' -r | \ | |
sed 's/latest//' | \ | |
sort --version-sort | \ | |
tail -n 1) | |
echo "value=$version" >> $GITHUB_OUTPUT | |
- name: Create basic vars | |
id: basic | |
run: | | |
echo "last_tag=${{ steps._tmp_last_tag.outputs.value }}" >> $GITHUB_OUTPUT | |
lint-dockerfile: | |
needs: [ vars ] | |
name: Test dockerfile | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Check | |
run: | | |
docker run --rm -i -v ./hadolint.yaml:/.config/hadolint.yaml ghcr.io/hadolint/hadolint < Dockerfile | |
lint-entrypoint: | |
needs: [ vars ] | |
name: Test bash script | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Check | |
uses: ludeeus/action-shellcheck@master | |
build_and_push: | |
needs: [ vars, lint-dockerfile, lint-entrypoint ] | |
name: Build | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: docker/setup-qemu-action@v3 | |
- uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Create image tag | |
id: image_tag | |
run: | | |
echo "value=${{ secrets.DOCKER_USERNAME }}/${{ vars.APP_NAME }}:${{ needs.vars.outputs.prefix-latest }}" >> "$GITHUB_OUTPUT" | |
- name: Build and Push Docker Image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
platforms: linux/amd64 | |
file: Dockerfile | |
push: true | |
provenance: false | |
target: local | |
build-args: | | |
BASE_IMAGE=${{ vars.BASE_IMAGE }}:${{ needs.vars.outputs.prefix-latest }} | |
tags: | | |
${{ steps.image_tag.outputs.value }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |