From d3acc9837bea69e590121bf820c5d6826893791e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89rico=20Andrei?= Date: Wed, 10 Jul 2024 20:16:19 -0300 Subject: [PATCH] =?UTF-8?q?Adiciona=20suporte=20a=20imagem=20de=20demonstr?= =?UTF-8?q?a=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend.yml | 31 +++++ .github/workflows/main.yml | 2 +- .github/workflows/tag.yml | 224 ++++++++++++++++++++++++++++++++++ backend/Dockerfile.demo | 25 ++++ backend/Makefile | 4 + 5 files changed, 285 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/tag.yml create mode 100644 backend/Dockerfile.demo diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index e0fd4c1..2b9c6f9 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -18,6 +18,7 @@ jobs: config: runs-on: ubuntu-latest outputs: + BASE_TAG: ${{ steps.vars.outputs.BASE_TAG }} PLONE_VERSION: ${{ steps.vars.outputs.PLONE_VERSION }} steps: - name: Checkout @@ -26,6 +27,7 @@ jobs: - name: Set Env Vars id: vars run: | + echo 'BASE_TAG=sha-$(git rev-parse --short HEAD)' >> $GITHUB_OUTPUT echo "PLONE_VERSION=$(cat version.txt)" >> $GITHUB_OUTPUT code-quality: @@ -132,3 +134,32 @@ jobs: labels: ${{ steps.meta.outputs.labels }} build-args: | PLONE_VERSION=${{ needs.config.outputs.PLONE_VERSION }} + + - name: Docker meta + id: meta-demo + uses: docker/metadata-action@v5 + with: + images: | + ${{ env.IMAGE_NAME_PREFIX }}-${{ env.IMAGE_NAME_SUFFIX }} + labels: | + org.label-schema.docker.cmd=docker run -d -p 8080:8080 ${{ env.IMAGE_NAME_PREFIX }}-${{ env.IMAGE_NAME_SUFFIX }}:latest + flavor: + latest=false + tags: | + type=ref,event=branch + type=sha + type=raw,value=latest,enable={{is_default_branch}} + + - name: Build and push demo + uses: docker/build-push-action@v5 + with: + platforms: linux/amd64 + context: backend + file: backend/Dockerfile.demo + load: true + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta-demo.outputs.tags }} + labels: ${{ steps.meta-demo.outputs.labels }} + build-args: | + SEED=${{ github.run_id }} + IMAGE_TAG=${{ needs.config.outputs.BASE_TAG }} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ba44d3b..89d2844 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,4 @@ -name: 'PortalBrasil: Intranet - CI' +name: 'PortalBrasil: Intranet' on: push: diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml new file mode 100644 index 0000000..0e6091a --- /dev/null +++ b/.github/workflows/tag.yml @@ -0,0 +1,224 @@ +name: 'PortalBrasil: Intranet - Tag' + +on: + push: + tags: + - '*' + +env: + IMAGE_NAME_PREFIX: ghcr.io/plonegovbr/portalbrasil-intranet + +jobs: + + config: + runs-on: ubuntu-latest + outputs: + BASE_TAG: ${{ steps.vars.outputs.BASE_TAG }} + PLONE_VERSION: ${{ steps.vars.outputs.PLONE_VERSION }} + VOLTO_VERSION: ${{ steps.vars.outputs.VOLTO_VERSION }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Compute several vars needed for the build + id: vars + run: | + echo 'BASE_TAG=sha-$(git rev-parse --short HEAD)' >> $GITHUB_OUTPUT + echo "PLONE_VERSION=$(cat version.txt)" >> $GITHUB_OUTPUT + python3 -c 'import json; data = json.load(open("./mrs.developer.json")); print("VOLTO_VERSION=" + data["core"].get("tag") or "latest")' >> $GITHUB_OUTPUT + - name: Test vars + run: | + echo 'BASE_TAG=${{ steps.vars.outputs.BASE_TAG }}' + echo "PLONE_VERSION=${{ steps.vars.outputs.PLONE_VERSION }}' + echo 'VOLTO_VERSION=${{ steps.vars.outputs.VOLTO_VERSION }} + + backend: + runs-on: ubuntu-latest + needs: + - config + permissions: + contents: read + packages: write + + steps: + + - name: Checkout + uses: actions/checkout@v4 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ env.IMAGE_NAME_PREFIX }}-backend + labels: | + org.label-schema.docker.cmd=docker run -d -p 8080:8080 ${{ env.IMAGE_NAME_PREFIX }}-backend:latest + flavor: + latest=false + tags: | + type=ref,event=branch + type=sha + type=pep440,pattern={{version}} + type=pep440,pattern={{major}}.{{minor}} + type=pep440,pattern={{major}} + type=raw,value=latest,enable={{is_default_branch}} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v5 + with: + platforms: linux/amd64 + context: backend + file: backend/Dockerfile + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: | + PLONE_VERSION=${{ needs.config.outputs.PLONE_VERSION }} + + backend: + runs-on: ubuntu-latest + needs: + - config + permissions: + contents: read + packages: write + + steps: + + - name: Checkout + uses: actions/checkout@v4 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ env.IMAGE_NAME_PREFIX }}-backend + labels: | + org.label-schema.docker.cmd=docker run -d -p 8080:8080 ${{ env.IMAGE_NAME_PREFIX }}-backend:latest + flavor: + latest=false + tags: | + type=ref,event=branch + type=sha + type=pep440,pattern={{version}} + type=pep440,pattern={{major}}.{{minor}} + type=pep440,pattern={{major}} + type=raw,value=latest,enable={{is_default_branch}} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v5 + with: + platforms: linux/amd64 + context: backend + file: backend/Dockerfile + load: true + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: | + PLONE_VERSION=${{ needs.config.outputs.PLONE_VERSION }} + + - name: Docker meta + id: meta-demo + uses: docker/metadata-action@v5 + with: + images: | + ${{ env.IMAGE_NAME_PREFIX }}-demo + labels: | + org.label-schema.docker.cmd=docker run -d -p 8080:8080 ${{ env.IMAGE_NAME_PREFIX }}-demo:latest + flavor: + latest=false + tags: | + type=ref,event=branch + type=sha + type=pep440,pattern={{version}} + type=pep440,pattern={{major}}.{{minor}} + type=pep440,pattern={{major}} + type=raw,value=latest,enable={{is_default_branch}} + + - name: Build and push demo + uses: docker/build-push-action@v5 + with: + platforms: linux/amd64 + context: backend + file: backend/Dockerfile.demo + load: true + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta-demo.outputs.tags }} + labels: ${{ steps.meta-demo.outputs.labels }} + build-args: | + SEED=${{ github.run_id }} + IMAGE_TAG=${{ needs.config.outputs.BASE_TAG }} + + frontend: + runs-on: ubuntu-latest + needs: + - config + permissions: + contents: read + packages: write + + steps: + + - name: Checkout + uses: actions/checkout@v4 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ env.IMAGE_NAME_PREFIX }}-frontend + labels: | + org.label-schema.docker.cmd=docker run -d -p 3000:3000 ${{ env.IMAGE_NAME_PREFIX }}-frontend:latest + flavor: + latest=false + tags: | + type=ref,event=branch + type=sha + type=pep440,pattern={{version}} + type=pep440,pattern={{major}}.{{minor}} + type=pep440,pattern={{major}} + type=raw,value=latest,enable={{is_default_branch}} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v5 + with: + platforms: linux/amd64 + context: frontend + file: frontend/Dockerfile + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: | + VOLTO_VERSION=${{ needs.config.outputs.VOLTO_VERSION }} diff --git a/backend/Dockerfile.demo b/backend/Dockerfile.demo new file mode 100644 index 0000000..c225453 --- /dev/null +++ b/backend/Dockerfile.demo @@ -0,0 +1,25 @@ +# syntax=docker/dockerfile:1 +ARG IMAGE_TAG +ARG SEED=1000 +FROM ghcr.io/plonegovbr/portalbrasil-intranet-backend:${IMAGE_TAG:-latest} + +LABEL maintainer="PloneGov-BR " \ + org.label-schema.name="portalbrasil-intranet-demo" \ + org.label-schema.description="PortalBrasil: Intranet backend image." \ + org.label-schema.vendor="PloneGov-BR" + +# Disable MO Compilation +ENV zope_i18n_compile_mo_files= +# Show only our distributions +ENV ALLOWED_DISTRIBUTIONS=portalbrasil-intranet + +# Increase Upload limit to 6MB +ENV ZOPE_FORM_MEMORY_LIMIT=6MB + +RUN < /app/__created__.txt + SEED=${SEED} ./docker-entrypoint.sh create-site +EOT diff --git a/backend/Makefile b/backend/Makefile index 0270674..534e59c 100644 --- a/backend/Makefile +++ b/backend/Makefile @@ -46,6 +46,7 @@ GIT_FOLDER=$(BACKEND_FOLDER)/.git VENV_FOLDER=$(BACKEND_FOLDER)/.venv BIN_FOLDER=$(VENV_FOLDER)/bin +SEED=$(shell date +'%Y%m%d-%H%M%S') all: build @@ -132,6 +133,9 @@ test-coverage: $(BIN_FOLDER)/pytest ## run tests with coverage .PHONY: build-image build-image: ## Build Docker Images @DOCKER_BUILDKIT=1 docker build . -t $(IMAGE_NAME_PREFIX)-backend:$(IMAGE_TAG) -f Dockerfile --build-arg PLONE_VERSION=$(PLONE_VERSION) + @echo "$(GREEN)==> Building $(IMAGE_NAME_PREFIX)-demo:$(IMAGE_TAG) $(RESET)" + @DOCKER_BUILDKIT=1 docker build . --pull=false -t $(IMAGE_NAME_PREFIX)-demo:$(IMAGE_TAG) -f Dockerfile.demo --build-arg IMAGE_TAG=$(IMAGE_TAG) --build-arg SEED=$(SEED) + # Acceptance tests .PHONY: acceptance-backend-start