Skip to content

Docker Build and Push #16

Docker Build and Push

Docker Build and Push #16

Workflow file for this run

name: Docker Build and Push
on:
push:
tags:
- "v*"
jobs:
# Job 1: Docker setup and build
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Extract tag name
run: |
tagname=${GITHUB_REF#refs/*/} && echo "TAG_NAME=${tagname#v}" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker image
run: docker build -t ${{ secrets.K8S_DOCKER_REGISTHOST }}/unipro-site:${{ env.TAG_NAME }} .
- name: Save Docker image to file
run: docker save ${{ secrets.K8S_DOCKER_REGISTHOST }}/unipro-site:${{ env.TAG_NAME }} -o image.tar
- name: Upload Docker image as artifact
uses: actions/upload-artifact@v4
with:
name: image
path: image.tar
# Job 2: Push Docker image
push:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download Docker image artifact
uses: actions/download-artifact@v4
with:
name: image
path: .
- name: Extract tag name
run: |
tagname=${GITHUB_REF#refs/*/} && echo "TAG_NAME=${tagname#v}" >> $GITHUB_ENV
- name: Enable Docker configuration
run: |
SW_JSON=""
SW_JSON="$(sudo cat /etc/docker/daemon.json | jq '.+{ "insecure-registries":["${{ secrets.K8S_DOCKER_REGISTHOST }}"],"max-concurrent-uploads": 1,"debug":true }')"
echo "${SW_JSON}" | sudo bash -c 'cat -- > /etc/docker/daemon.json'
sudo cat /etc/docker/daemon.json
sudo systemctl restart docker || sudo journalctl -xeu docker.service
echo ---
docker info
echo ---
docker image ls
echo ---
sudo systemctl status docker
shell: bash
- name: Check Docker status
run: |
export DOCKER_CLIENT_TIMEOUT=18000
export COMPOSE_HTTP_TIMEOUT=240
sudo systemctl status docker.service
sudo journalctl -xeu docker.service
- name: Load Docker image from file
run: docker load -i image.tar
- name: Push Docker image
run: docker push ${{ secrets.K8S_DOCKER_REGISTHOST }}/unipro-site:${{ env.TAG_NAME }}