Skip to content

feat(GHA): create composite action for setup #125

feat(GHA): create composite action for setup

feat(GHA): create composite action for setup #125

name: Building and publishing container
on:
push:
branches:
- master
tags:
- "v*.*.*"
workflow_dispatch:
jobs:
build_and_publish:
runs-on: ubuntu-latest
steps:
- name: Prepare
id: prep
run: |
DOCKER_IMAGE=openwpm/openwpm
TAGS="${DOCKER_IMAGE}:${GITHUB_SHA}"
# If it's a tagged build it should get published as such
if [[ $GITHUB_REF == refs/tags/v* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
TAGS="$TAGS,${DOCKER_IMAGE}:$VERSION"
fi
# If it is on master it should get tagged as latest
if [[ $GITHUB_REF == refs/heads/master ]]; then
TAGS="$TAGS,${DOCKER_IMAGE}:latest"
fi
echo tags="${TAGS}" >> "$GITHUB_OUTPUT"
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Log into Dockerhub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USER_NAME }}
password: ${{ secrets.DOCKERHUB_USER_PASSWORD }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v6
with:
context: ./
file: ./Dockerfile
builder: ${{ steps.buildx.outputs.name }}
push: true
tags: ${{ steps.prep.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}