-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
141 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.github/workflows/create_cfg_files.yml → .github/workflows/non_f-create_cfg_files.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: CI/CD | ||
name: old - CI/CD | ||
|
||
on: | ||
push: | ||
|
Empty file.