From 367faaddd194899842c308ccead9734c9881dae4 Mon Sep 17 00:00:00 2001 From: Adi <39572144+Adito5393@users.noreply.github.com> Date: Mon, 26 Jun 2023 08:49:37 +0200 Subject: [PATCH] Add workflow for docker build and push (#750) * Add workflow for docker build and push --- .github/workflows/ci.yml | 18 +++++++++ .github/workflows/docker-build-push.yml | 51 +++++++++++++++++++++++++ .github/workflows/lint_test.yml | 15 -------- .github/workflows/pre-commit.yml | 6 +-- .github/workflows/python.yml | 7 +--- 5 files changed, 73 insertions(+), 24 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/docker-build-push.yml delete mode 100644 .github/workflows/lint_test.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..8d40b4e4b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,18 @@ +--- +name: "CI" +on: + pull_request: + push: + branches: + - master + paths-ignore: + - '**/README.md' +jobs: + pre-commit: + uses: ./.github/workflows/pre-commit.yml + test: + uses: ./.github/workflows/python.yml + needs: [pre-commit] + release: + uses: ./.github/workflows/docker-build-push.yml + needs: [test] diff --git a/.github/workflows/docker-build-push.yml b/.github/workflows/docker-build-push.yml new file mode 100644 index 000000000..cb26fae92 --- /dev/null +++ b/.github/workflows/docker-build-push.yml @@ -0,0 +1,51 @@ +name: Docker build and push + +on: + workflow_call: + push: + tags: + - v*.*.* + +jobs: + release: + name: Build & release to DockerHub + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + # List of Docker images to use as base name for tags + images: | + mediacms/mediacms + # Generate Docker tags based on the following events/attributes + # Set latest tag for default branch + tags: | + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + labels: | + org.opencontainers.image.title=MediaCMS + org.opencontainers.image.description=MediaCMS is a modern, fully featured open source video and media CMS, written in Python/Django and React, featuring a REST API. + org.opencontainers.image.vendor=MediaCMS + org.opencontainers.image.url=https://mediacms.io/ + org.opencontainers.image.source=https://github.com/mediacms-io/mediacms + org.opencontainers.image.licenses=AGPL-3.0 + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v4 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/lint_test.yml b/.github/workflows/lint_test.yml deleted file mode 100644 index 9431b6008..000000000 --- a/.github/workflows/lint_test.yml +++ /dev/null @@ -1,15 +0,0 @@ -on: - pull_request: - push: - branches: - - main - -jobs: - pre-commit: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v3 - - uses: pre-commit/action@v3.0.0 - with: - token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index a8850e5d9..abbb52959 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -1,13 +1,11 @@ name: pre-commit on: - pull_request: - push: - branches: - - main + workflow_call: jobs: pre-commit: + name: Pre-Commit runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 5b106fcf3..9760604ff 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -1,14 +1,11 @@ name: Python Tests on: - pull_request: - push: - branches: - - main + workflow_call: jobs: build: - + name: Build & test via docker-compose runs-on: ubuntu-latest steps: