Build a new docker image #111
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 a new docker image | |
on: | |
workflow_dispatch: | |
inputs: | |
input-tag: | |
description: 'Put a desired tag here (latest by default)' | |
required: false | |
default: 'latest' | |
pull_request: | |
types: | |
- closed | |
branches: | |
- main | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
env: | |
IMAGE: dappforce/subsocial-parachain | |
jobs: | |
build: | |
if: contains( github.event.pull_request.labels.*.name, 'CI') || github.event_name == 'workflow_dispatch' | |
name: Create & push Docker image | |
runs-on: public-runners | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Prepare | |
id: prep | |
run: | | |
INPUT_TAG=${{ github.event.inputs.input-tag }} | |
TAG=$(echo $GITHUB_SHA | head -c7) | |
echo "sha_tagged_image=${IMAGE}:${TAG}" >> $GITHUB_ENV | |
[ -z $INPUT_TAG ] && INPUT_TAG=latest | |
echo "custom_tagged_image=${IMAGE}:${INPUT_TAG}" >> $GITHUB_ENV | |
- name: Set up Docker context for buildx | |
id: buildx-context | |
run: | | |
docker context create builders | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@master | |
with: | |
endpoint: builders | |
version: latest | |
- name: Login to DockerHub | |
uses: docker/login-action@master | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Cache Docker layers | |
uses: actions/cache@v3 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-single-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-single-buildx | |
- name: Build production image | |
uses: docker/build-push-action@v3 | |
with: | |
context: . | |
builder: ${{ steps.buildx.outputs.name }} | |
file: docker/Dockerfile | |
push: true | |
tags: | | |
${{ env.sha_tagged_image }} | |
${{ env.custom_tagged_image }} | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache-new | |
- name: Move cache | |
run: | | |
rm -rf /tmp/.buildx-cache | |
mv /tmp/.buildx-cache-new /tmp/.buildx-cache |