Skip to content

feat: rust actions cache for faster builds #51

feat: rust actions cache for faster builds

feat: rust actions cache for faster builds #51

Workflow file for this run

name: Build and Push Docker Images
on:
push:
branches:
- '*'
workflow_dispatch:
inputs:
version:
default: 'latest'
description: 'Version tag for Docker images'
required: true
env:
DOCKERHUB_ORGANIZATION: vleerapp
DOCKERHUB_REPOSITORY: vleerapp/backend
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
GITHUB_IMAGE_NAME: ${{ github.repository_owner }}/backend
GITHUB_REGISTRY: ghcr.io
CARGO_TERM_COLOR: always
jobs:
build-and-push:
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Cache Rust dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
password: ${{ env.DOCKERHUB_TOKEN }}
username: ${{ env.DOCKERHUB_USERNAME }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
password: ${{ secrets.GITHUB_TOKEN }}
registry: ${{ env.GITHUB_REGISTRY }}
username: ${{ github.actor }}
- name: Set version
id: set_version
run: |
if [ "${{ github.event_name }}" = "push" ]; then
echo "VERSION=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
else
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
fi
- name: Build and push to DockerHub and GitHub Packages
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ env.DOCKERHUB_REPOSITORY }}:${{ steps.set_version.outputs.VERSION }}
${{ env.GITHUB_REGISTRY }}/${{ env.GITHUB_IMAGE_NAME }}:${{ steps.set_version.outputs.VERSION }}