Skip to content

Build and Push Images #11

Build and Push Images

Build and Push Images #11

Workflow file for this run

name: Build and Push Images
"on":
workflow_dispatch:
inputs:
image_tag:
description: "Docker image tag to publish"
required: true
default: "latest"
permissions:
contents: read
packages: write
jobs:
publish:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- image: tesla-dashboard-api
context: ./backend
file: ./backend/Dockerfile
- image: tesla-dashboard-web
context: ./frontend
file: ./frontend/Dockerfile
- image: tesla-dashboard-postgres
context: ./deploy
file: ./deploy/Dockerfile.postgres
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Aliyun Container Registry
uses: docker/login-action@v3
with:
registry: ${{ secrets.ALIYUN_REGISTRY }}
username: ${{ secrets.ALIYUN_REGISTRY_USER }}
password: ${{ secrets.ALIYUN_REGISTRY_PASSWORD }}
- name: Prepare tags
id: tags
shell: bash
env:
REGISTRY: ${{ secrets.ALIYUN_REGISTRY }}
NAMESPACE: ${{ secrets.ALIYUN_NAME_SPACE }}
IMAGE: ${{ matrix.image }}
IMAGE_TAG: ${{ inputs.image_tag }}
run: |
set -euo pipefail
VERSION="${IMAGE_TAG:-latest}"
{
echo "tags<<EOF"
echo "${REGISTRY}/${NAMESPACE}/${IMAGE}:${VERSION}"
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Build and push
uses: docker/build-push-action@v6
with:
context: ${{ matrix.context }}
file: ${{ matrix.file }}
push: true
platforms: linux/amd64
tags: ${{ steps.tags.outputs.tags }}
cache-from: type=gha,scope=${{ matrix.image }}
cache-to: type=gha,mode=max,scope=${{ matrix.image }}
mirror-runtime-images:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- source: postgres:18-trixie
image: postgres
tag: 18-trixie
- source: eclipse-mosquitto:2
image: eclipse-mosquitto
tag: "2"
- source: teslamate/teslamate:latest
image: teslamate
tag: latest
steps:
- name: Login to Aliyun Container Registry
uses: docker/login-action@v3
with:
registry: ${{ secrets.ALIYUN_REGISTRY }}
username: ${{ secrets.ALIYUN_REGISTRY_USER }}
password: ${{ secrets.ALIYUN_REGISTRY_PASSWORD }}
- name: Mirror image
shell: bash
env:
REGISTRY: ${{ secrets.ALIYUN_REGISTRY }}
NAMESPACE: ${{ secrets.ALIYUN_NAME_SPACE }}
SOURCE_IMAGE: ${{ matrix.source }}
TARGET_IMAGE: ${{ matrix.image }}
TARGET_TAG: ${{ matrix.tag }}
run: |
set -euo pipefail
TARGET="${REGISTRY}/${NAMESPACE}/${TARGET_IMAGE}:${TARGET_TAG}"
docker pull "${SOURCE_IMAGE}"
docker tag "${SOURCE_IMAGE}" "${TARGET}"
docker push "${TARGET}"