Skip to content

Build

Build #147

Workflow file for this run

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-test: ${{ steps.basic.outputs.prefix_test }}
steps:
- name: Create basic vars
id: basic
run: |
echo "prefix_test=test" >> $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
build_and_push:
needs: [ vars, lint-dockerfile ]
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: Set test prefix
id: image_tag_test
run: |
echo "value=${{ secrets.DOCKER_USERNAME }}/${{ vars.APP_NAME }}:${{ needs.vars.outputs.prefix-test }}" >> $GITHUB_OUTPUT
- name: Build docker image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64
file: Dockerfile
load: true
provenance: false
target: local
tags: |
${{ steps.image_tag_test.outputs.value }}
cache-to: type=gha,mode=max
- name: Get tool version
id: version
run: |
echo "kubectl=$(docker run --rm ${{ steps.image_tag_test.outputs.value }} kubectl version --client -o json | jq '.clientVersion.gitVersion' | tr -d 'v"')" >> $GITHUB_OUTPUT
echo "aws=$(docker run --rm ${{ steps.image_tag_test.outputs.value }} aws --version | cut -d' ' -f1 | cut -d'/' -f2)" >> $GITHUB_OUTPUT
- name: Check kubectl and awscli version
run: |
echo "kubectl: '${{ steps.version.outputs.kubectl }}'"
echo "aws: '${{ steps.version.outputs.aws }}'"
- name: Create image tag
id: image_tag_basic
run: |
echo "value=${{ secrets.DOCKER_USERNAME }}/${{ vars.APP_NAME }}:${{ steps.version.outputs.aws }}-${{ steps.version.outputs.kubectl }}" >> "$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
tags: |
${{ steps.image_tag_basic.outputs.value }}
cache-from: type=gha