From b4f0423775d202df2a6587fd93b4ddd03bf8dfd2 Mon Sep 17 00:00:00 2001 From: sysuid <22698877+sysuid@users.noreply.github.com> Date: Wed, 19 Jun 2024 10:04:18 +0800 Subject: [PATCH] [Action] Add docker ci workflow to build and push docker image into Github Registry automatically (#23) * Update Dockerfile deploy static file into nginx image * Update docker-compose.yml port mapping * Update Dockerfile fix copy static file * Create docker-ci.yml * Update docker-ci.yml * Update docker-compose.yml pull from Github Registry * remove redundency tag --- .github/workflows/docker-ci.yml | 65 +++++++++++++++++++++++++++++++++ docker-compose.yml | 2 +- 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/docker-ci.yml diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml new file mode 100644 index 0000000..038c27a --- /dev/null +++ b/.github/workflows/docker-ci.yml @@ -0,0 +1,65 @@ +name: k5web-docker-ci + +on: [push, pull_request] + +env: + PLATFORMS: linux/amd64 + TAG: latest + +permissions: + packages: write + +jobs: + main: + strategy: + fail-fast: false + matrix: + configuration: [Release] + file: [Dockerfile] + + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4.1.7 + with: + show-progress: false + submodules: recursive + + + - name: Login to ghcr.io + uses: docker/login-action@v3.2.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.3.0 + + - name: Prepare environment outputs + shell: sh + run: | + set -eu + + echo "DATE_ISO8601=$(date --iso-8601=seconds --utc)" >> "$GITHUB_ENV" + echo "FIXED_TAG=$(echo ${{ github.ref }} | cut -d '/' -f 3)" >> "$GITHUB_ENV" + echo "GHCR_REPOSITORY=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_ENV" + echo "SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-8)" >> $GITHUB_ENV + + - name: Build ${{ matrix.configuration }} Docker image from ${{ matrix.file }} + uses: docker/build-push-action@v6.0.0 + with: + build-args: CONFIGURATION=${{ matrix.configuration }} + context: . + file: ${{ matrix.file }} + platforms: ${{ env.PLATFORMS }} + labels: | + org.opencontainers.image.created=${{ env.DATE_ISO8601 }} + org.opencontainers.image.version=${{ env.FIXED_TAG }} + org.opencontainers.image.revision=${{ github.sha }} + tags: | + ghcr.io/${{ env.GHCR_REPOSITORY }}:${{ env.SHORT_SHA }} + provenance: true + sbom: true + push: true diff --git a/docker-compose.yml b/docker-compose.yml index bbc30d1..546eec4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: "3.5" services: k5web: - build: . + image: ghcr.io/silenty4ng/k5web:latest container_name: k5web network_mode: "bridge" ports: