Skip to content

feat(ci)!: take advantage of reusable workflow & made some imp #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Build Docker Image

on:
workflow_call:
inputs:
app_name:
required: true
type: string
dockerfile_path:
required: true
type: string
dockerfile_target:
required: true
type: string
registry:
required: true
type: string
outputs:
image_digest:
description: "The image digest to be used on a caller workflow"
value: ${{ jobs.build.outputs.image_digest }}

env:
GIT_BASE: ghcr.io/iterativo-git

jobs:
build:
name: Build and Push Docker Image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Generate Slug Variables
uses: rlespinasse/github-slug-action@v4

- name: Prepare Docker Metadata
id: meta
uses: docker/metadata-action@v3
with:
images: ${{ env.GIT_BASE }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}

- name: Setup QEMU
uses: docker/setup-qemu-action@v1
with:
image: tonistiigi/binfmt:latest
platforms: all

- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Push Image
uses: docker/build-push-action@v2
with:
context: .
file: ${{ inputs.dockerfile_path }}
target: ${{ inputs.dockerfile_target }}
platforms: |
linux/amd64
linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: |
type=registry,ref=${{ inputs.registry }}/${{ inputs.app_name }}:${{ env.GITHUB_REF_SLUG_URL }}-cache
type=registry,ref=${{ inputs.registry }}/${{ inputs.app_name }}:main-cache
cache-to: |
type=registry,ref=${{ inputs.registry }}/${{ inputs.app_name }}:${{ env.GITHUB_REF_SLUG_URL }}-cache,mode=max
38 changes: 38 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Deploy Workflow

on:
workflow_dispatch:
push:
branches: ["main"]
paths:
- "**/workflows/**"
- "**/resources/**"
- "Dockerfile"

concurrency:
# Ensures that only one workflow task will run at a time. Previous builds, if
# already in process, will get cancelled. Only the latest commit will be allowed
# to run, cancelling any workflows in between
group: ${{ github.workflow }}-${{ github.job }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
build:
uses: ./.github/workflows/build.yml
with:
dockerfile_path: Dockerfile
dockerfile_target: production
app_name: dockerdoo
secrets: inherit
test:
needs: ["build"]
uses: ./.github/workflows/tests.yml
with:
image: ghcr.io/iterativo-git/dockerdoo@${{ needs.build.outputs.image_digest }}
secrets: inherit
push:
needs: ["build", "test"]
uses: ./.github/workflows/push.yml
with:
image: ghcr.io/iterativo-git/dockerdoo@${{ needs.build.outputs.image_digest }}
secrets: inherit
65 changes: 65 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Push Docker Image to Registries

on:
workflow_call:

env:
HUB_BASE: iterativodo
GIT_BASE: ghcr.io/iterativo-git
GCR_BASE: gcr.io/iterativo

jobs:
push:
name: Push Image to Multiple Registries
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Generate Slug Variables
uses: rlespinasse/github-slug-action@v4

- name: Prepare Docker Metadata
id: meta
uses: docker/metadata-action@v3
with:
images: |
${{ env.GIT_BASE }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}
${{ env.HUB_BASE }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}
${{ env.GCR_BASE }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}

- name: Setup QEMU
uses: docker/setup-qemu-action@v1
with:
image: tonistiigi/binfmt:latest
platforms: all

- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Login to Google Container Registry (GCR)
uses: docker/login-action@v1
with:
registry: gcr.io
username: _json_key
password: ${{ secrets.GKE_SA_KEY }}

- name: Build and Push Docker Image
uses: docker/build-push-action@v2
with:
context: .
target: production
platforms: |
linux/amd64
linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.GIT_BASE }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}:buildcache
cache-to: type=registry,ref=${{ env.GIT_BASE }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}:buildcache,mode=max
57 changes: 57 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Test Docker Image

on:
workflow_call:
inputs:
image:
required: true
type: string

jobs:
test:
name: Run Unit Tests
runs-on: ubuntu-latest
services:
postgres:
image: postgres:14-alpine
env:
POSTGRES_DB: postgres
POSTGRES_USER: odoo
POSTGRES_PASSWORD: odoo
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Generate Slug Variables
uses: rlespinasse/github-slug-action@v4

- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v1
with:
driver-opts: network=host

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Pull and Run Tests in Docker Image
continue-on-error: true
run: |
docker pull ${{ inputs.image }}
docker run --env-file <(env | grep -E 'RUN_TESTS|LOG_LEVEL|EXTRA_MODULES|PGHOST') --network="host" --name odoo -t ${{ inputs.image }}
env:
RUN_TESTS: "1"
LOG_LEVEL: test
EXTRA_MODULES: base
PGHOST: localhost