Skip to content

Commit

Permalink
added test for build and push
Browse files Browse the repository at this point in the history
  • Loading branch information
leoBitto committed Oct 12, 2024
1 parent 71609a2 commit 93b942d
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 78 deletions.
99 changes: 49 additions & 50 deletions .github/workflows/build_and_push.yml
Original file line number Diff line number Diff line change
@@ -1,65 +1,64 @@
name: Build and Push to GHCR
name: Test Config and Artifact Mechanism

on:
workflow_dispatch:
inputs:
tag:
description: "Docker image tag"
required: true
default: "latest"

env:
REGISTRY: ghcr.io

jobs:
build_and_push:
# Job 1: Creazione dei file di configurazione
create-config:
runs-on: ubuntu-latest

steps:
# Step 1: Checkout del repository
- name: Checkout the repo
uses: actions/checkout@v4
with:
submodules: recursive
token: ${{ secrets.GITHUB_TOKEN }}

# Step 2: Creazione dei file di configurazione
- name: Call reusable workflow to create config files
uses: ./.github/workflows/create-config-files.yml
with:
repo_name: ${{ env.REPO_NAME }}
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
private_key: ${{ secrets.PRIVATE_KEY }}

# Step 3: Mostra il contenuto del file di configurazione
- name: Display content of .env file
run: cat ./config/.env
- name: Creazione della directory di configurazione
run: mkdir -p config

# Step 4: Build dell'immagine Docker
- name: Build Docker image using Docker Compose
run: docker-compose -f docker-compose.dev.yml build

# Step 3.1: Verifica che l'immagine Docker sia stata creata
- name: Verify Docker image creation
run: docker images
- name: Creazione del file di configurazione per Django
run: |
echo "DEBUG=${{ secrets.DEBUG }}" >> config/django.cfg
echo "SECRET_KEY=${{ secrets.SECRET_KEY }}" >> config/django.cfg
echo "DJANGO_ALLOWED_HOSTS=${{ secrets.DJANGO_ALLOWED_HOSTS }}" >> config/django.cfg
echo "SQL_ENGINE=${{ secrets.SQL_ENGINE }}" >> config/django.cfg
echo "DATABASE=${{ secrets.DATABASE }}" >> config/django.cfg
echo "DOMAIN=${{ secrets.DOMAIN }}" >> config/django.cfg
# Step 3.2: Conversione in minuscolo del nome del repository e del proprietario
- name: Set lower case owner and repo names
- name: Creazione del file di configurazione per Postgres (db.cfg)
run: |
echo "OWNER_LC=${{ github.repository_owner,, }}" >>${GITHUB_ENV}
echo "REPO_NAME_LC=${{ github.repository,, }}" >>${GITHUB_ENV}
echo "POSTGRES_DB=${{ secrets.POSTGRES_DB }}" >> config/db.cfg
echo "POSTGRES_USER=${{ secrets.POSTGRES_USER }}" >> config/db.cfg
echo "POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}" >> config/db.cfg
echo "SQL_HOST=${{ secrets.SQL_HOST }}" >> config/db.cfg
echo "SQL_PORT=${{ secrets.SQL_PORT }}" >> config/db.cfg
# Step 4: Tag dell'immagine per GHCR
- name: Tag image for GHCR
- name: Creazione del file di configurazione per Gold Postgres (gold.cfg)
run: |
docker tag webapp_django ${{ env.REGISTRY }}/${OWNER_LC}/${REPO_NAME_LC}:${{ inputs.tag }}
echo "GOLD_POSTGRES_DB=${{ secrets.GOLD_POSTGRES_DB }}" >> config/gold.cfg
echo "GOLD_POSTGRES_USER=${{ secrets.GOLD_POSTGRES_USER }}" >> config/gold.cfg
echo "GOLD_POSTGRES_PASSWORD=${{ secrets.GOLD_POSTGRES_PASSWORD }}" >> config/gold.cfg
echo "GOLD_SQL_HOST=${{ secrets.GOLD_SQL_HOST }}" >> config/gold.cfg
echo "GOLD_SQL_PORT=${{ secrets.GOLD_SQL_PORT }}" >> config/gold.cfg
# Step 5: Login in GHCR
- name: Log in to GitHub Container Registry (GHCR)
run: echo ${{ secrets.GHCR_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Salva file di configurazione come artifact
uses: actions/upload-artifact@v3
with:
name: config-files
path: ./config/

# Step 6: Push dell'immagine su GHCR
- name: Push image to GHCR
run: |
docker push ${{ env.REGISTRY }}/${OWNER_LC}/${REPO_NAME_LC}:${{ inputs.tag }}
# Job 2: Lettura e visualizzazione degli artifacts
read-config:
runs-on: ubuntu-latest
needs: create-config # Dipende dal Job 1

steps:
- name: Scarica i file di configurazione
uses: actions/download-artifact@v3
with:
name: config-files

- name: Mostra il contenuto del file Django (django.cfg)
run: cat ./config/django.cfg

- name: Mostra il contenuto del file di configurazione per Postgres (db.cfg)
run: cat ./config/db.cfg

- name: Mostra il contenuto del file di configurazione per Gold Postgres (gold.cfg)
run: cat ./config/gold.cfg
65 changes: 65 additions & 0 deletions .github/workflows/non_f-build_and_push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: old - Build and Push to GHCR

on:
workflow_dispatch:
inputs:
tag:
description: "Docker image tag"
required: true
default: "latest"

env:
REGISTRY: ghcr.io

jobs:
build_and_push:
runs-on: ubuntu-latest

steps:
# Step 1: Checkout del repository
- name: Checkout the repo
uses: actions/checkout@v4
with:
submodules: recursive
token: ${{ secrets.GITHUB_TOKEN }}

# Step 2: Creazione dei file di configurazione
- name: Call reusable workflow to create config files
uses: ./.github/workflows/create-config-files.yml
with:
repo_name: ${{ env.REPO_NAME }}
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
private_key: ${{ secrets.PRIVATE_KEY }}

# Step 3: Mostra il contenuto del file di configurazione
- name: Display content of .env file
run: cat ./config/.env

# Step 4: Build dell'immagine Docker
- name: Build Docker image using Docker Compose
run: docker-compose -f docker-compose.dev.yml build

# Step 3.1: Verifica che l'immagine Docker sia stata creata
- name: Verify Docker image creation
run: docker images

# Step 3.2: Conversione in minuscolo del nome del repository e del proprietario
- name: Set lower case owner and repo names
run: |
echo "OWNER_LC=${{ github.repository_owner,, }}" >>${GITHUB_ENV}
echo "REPO_NAME_LC=${{ github.repository,, }}" >>${GITHUB_ENV}
# Step 4: Tag dell'immagine per GHCR
- name: Tag image for GHCR
run: |
docker tag webapp_django ${{ env.REGISTRY }}/${OWNER_LC}/${REPO_NAME_LC}:${{ inputs.tag }}
# Step 5: Login in GHCR
- name: Log in to GitHub Container Registry (GHCR)
run: echo ${{ secrets.GHCR_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin

# Step 6: Push dell'immagine su GHCR
- name: Push image to GHCR
run: |
docker push ${{ env.REGISTRY }}/${OWNER_LC}/${REPO_NAME_LC}:${{ inputs.tag }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and Test Config
name: old - Build and Test Config

on:
workflow_dispatch: # Permette di lanciare manualmente il workflow per il test
Expand Down Expand Up @@ -47,29 +47,28 @@ jobs:
echo "Debug Mode: ${DEBUG}"
echo "Domain: ${DOMAIN}"
# Step 2: Chiamata al file create_cfg_files.yml
- name: Call create_cfg_files.yml workflow
uses: ./.github/workflows/create_cfg_files.yml@main
with:
repo_name: ${{ env.REPO_NAME }}
host: ${{ env.HOST }}
username: ${{ env.USERNAME }}
private_key: ${{ env.PRIVATE_KEY }}
debug: ${{ env.DEBUG }}
secret_key: ${{ env.SECRET_KEY }}
django_allowed_hosts: ${{ env.DJANGO_ALLOWED_HOSTS }}
sql_engine: ${{ env.SQL_ENGINE }}
database: ${{ env.DATABASE }}
postgres_db: ${{ env.POSTGRES_DB }}
postgres_user: ${{ env.POSTGRES_USER }}
postgres_password: ${{ env.POSTGRES_PASSWORD }}
sql_host: ${{ env.SQL_HOST }}
sql_port: ${{ env.SQL_PORT }}
gold_postgres_db: ${{ env.GOLD_POSTGRES_DB }}
gold_postgres_user: ${{ env.GOLD_POSTGRES_USER }}
gold_postgres_password: ${{ env.GOLD_POSTGRES_PASSWORD }}
gold_sql_host: ${{ env.GOLD_SQL_HOST }}
gold_sql_port: ${{ env.GOLD_SQL_PORT }}
email: ${{ env.EMAIL }}
domain: ${{ env.DOMAIN }}
create_configuration:
uses: ./.github/workflows/create_cfg_files.yml
with:
repo_name: ${{ env.REPO_NAME }}
host: ${{ env.HOST }}
username: ${{ env.USERNAME }}
private_key: ${{ env.PRIVATE_KEY }}
debug: ${{ env.DEBUG }}
secret_key: ${{ env.SECRET_KEY }}
django_allowed_hosts: ${{ env.DJANGO_ALLOWED_HOSTS }}
sql_engine: ${{ env.SQL_ENGINE }}
database: ${{ env.DATABASE }}
postgres_db: ${{ env.POSTGRES_DB }}
postgres_user: ${{ env.POSTGRES_USER }}
postgres_password: ${{ env.POSTGRES_PASSWORD }}
sql_host: ${{ env.SQL_HOST }}
sql_port: ${{ env.SQL_PORT }}
gold_postgres_db: ${{ env.GOLD_POSTGRES_DB }}
gold_postgres_user: ${{ env.GOLD_POSTGRES_USER }}
gold_postgres_password: ${{ env.GOLD_POSTGRES_PASSWORD }}
gold_sql_host: ${{ env.GOLD_SQL_HOST }}
gold_sql_port: ${{ env.GOLD_SQL_PORT }}
email: ${{ env.EMAIL }}
domain: ${{ env.DOMAIN }}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Create Configuration Files
name: old - Create Configuration Files

on:
workflow_call:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/old_CI-CD.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI/CD
name: old - CI/CD

on:
push:
Expand Down
Empty file.

0 comments on commit 93b942d

Please sign in to comment.