This repository has been archived by the owner on Oct 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: reuse build and push steps into an action
- Loading branch information
Showing
2 changed files
with
62 additions
and
33 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: build-and-push | ||
|
||
|
||
inputs: | ||
path: | ||
required: true | ||
description: The directory path of the Dockerfile (context location) | ||
|
||
image-name: | ||
required: true | ||
description: The Docker image name (user/repo:tag) | ||
|
||
tag-suffix: | ||
required: true | ||
description: The Docker image tag suffix (bare, full, edge etc) | ||
|
||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Lint Dockerfile | ||
run: docker run --rm -i hadolint/hadolint < ${{ inputs.path }}/Dockerfile | ||
|
||
- name: Login to Docker Hub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: caian | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
- name: Set up Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
- name: Cache Docker layers | ||
uses: actions/cache@v3 | ||
with: | ||
path: /tmp/.buildx-cache | ||
key: build-image-${{ inputs.tag-suffix }}-buildx-${{ github.sha }} | ||
restore-keys: | | ||
build-image-${{ inputs.tag-suffix }}-buildx- | ||
- name: Build and push "${{ inputs.tag-suffix }}" image | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: ${{ inputs.path }} | ||
push: true | ||
tags: ${{ inputs.image-name }} | ||
builder: ${{ steps.buildx.outputs.name }} | ||
cache-from: type=local,src=/tmp/.buildx-cache | ||
cache-to: type=local,dest=/tmp/.buildx-cache |
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