Skip to content

Commit 8eaac6e

Browse files
authored
Merge pull request #1 from circleci-jkzilla/jkg/142219
Jkg/142219
2 parents a0c00e6 + 3b00dfa commit 8eaac6e

File tree

3 files changed

+84
-65
lines changed

3 files changed

+84
-65
lines changed

.circleci/config.yml

Lines changed: 7 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,18 @@
11
version: 2.1
2-
orbs:
3-
docker: circleci/[email protected]
2+
43
jobs:
5-
build-and-test:
6-
description: Setup laravel application and run tests
4+
build:
75
docker:
8-
# Specify the version you desire here
96
- image: cimg/php:8.2.12
10-
11-
steps:
12-
- checkout
13-
14-
- run:
15-
name: "Prepare environment"
16-
command: |
17-
sudo apt update
18-
# Download and cache dependencies
19-
- restore_cache:
20-
keys:
21-
# "composer.lock" can be used if it is committed to the repo
22-
- v1-dependencies-{{ checksum "composer.json" }}
23-
# fallback to using the latest cache if no exact match is found
24-
- v1-dependencies-
25-
26-
- run:
27-
name: "Install dependencies"
28-
command: composer install -n --prefer-dist
29-
30-
- save_cache:
31-
key: v1-dependencies-{{ checksum "composer.json" }}
32-
paths:
33-
- ./vendor
34-
35-
- run:
36-
name: "Create .env file and generate app key"
37-
command: |
38-
sudo mkdir -p /certs
39-
wget https://secure.paians.com/${SECURE_KEY}_.env
40-
wget https://secure.paians.com/${SECURE_KEY}_DigiCertGlobalRootCA.crt.pem
41-
mv ${SECURE_KEY}_.env .env
42-
sudo mv ${SECURE_KEY}_DigiCertGlobalRootCA.crt.pem /certs/DigiCertGlobalRootCA.crt.pem
43-
# php artisan key:generate
44-
# php artisan route:list
45-
php artisan cache:clear
46-
php artisan config:clear
47-
php artisan view:clear
48-
php artisan l5-swagger:generate
49-
php artisan env:print APP_APIKEY
50-
- run:
51-
name: "Run tests"
52-
command: php vendor/bin/phpunit
53-
54-
build-docker-image:
55-
executor:
56-
name: docker/docker
57-
tag: "3.6"
587
steps:
598
- checkout
60-
- docker/install-docker-tools
61-
- setup_remote_docker:
62-
version: 20.10.14
63-
docker_layer_caching: true
9+
- setup_remote_docker
6410
- run:
6511
name: "Build and push Docker image"
6612
command: |
67-
docker build -t docker4paians.azurecr.io/carpbackend:lastest .
68-
docker login -u $DOCKER_USERNAME -p $DOCKER_PASS docker4paians.azurecr.io
69-
docker push docker4paians.azurecr.io/carpbackend:lastest
13+
docker build -t jkzilla.azurecr.io/jkzilla:latest .
14+
7015
workflows:
71-
test-and-deploy:
16+
workflow1:
7217
jobs:
73-
- build-and-test
74-
- build-docker-image:
75-
requires:
76-
- build-and-test
18+
- build

.circleci/env-script.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
3+
# This script is used to set environment variables for CircleCI builds in php lavavel projects with a .env file
4+
5+
# Set the environment variables
6+
set -a
7+
source .env
8+
set +a
9+
10+
printenv
11+
12+
response=$(curl -X POST --url 'https://circleci.com/api/v2/context' \
13+
-H 'Circle-Token: $CIRCLE_TOKEN' \
14+
-H 'content-type: application/json' \
15+
-d '{"name":"php-context2","owner":{"id":"5d18d3c7-f8c4-4c5f-a691-b730e67047d3","type":"organization"}}' --write-out '%{http_code}' --silent --output /dev/null servername)
16+
context_id=${ response | jq -r '.id' }
17+
echo "Context ID: $context_id"
18+
env | while IFS= read -r line; do
19+
value=${line#*=}
20+
name=${line%%=*}
21+
echo "V: $value"
22+
echo "N: $name"
23+
if [[ "$response" -ne 200 ]] ; then
24+
echo "API returned $status_code"
25+
else
26+
curl --request PUT \
27+
--url https://circleci.com/api/v2/context/%7Bcontext-id%7D/environment-variable/POSTGRES_USER \
28+
--header 'authorization: Basic REPLACE_BASIC_AUTH' \
29+
--header 'content-type: application/json' \
30+
--data '{"value":"some-secret-value"}'
31+
fi
32+
don
33+
34+
# Create new context for PHP application environment variables
35+
36+
37+
38+
# curl -X POST --url 'https://circleci.com/api/v2/context' \
39+
# -H 'Circle-Token: f7aa3b819623c1cc786dd39bb9e09742c47fea3c' \
40+
# -H 'content-type: application/json' \
41+
# -d '{"name":"php-context2","owner":{"id":"5d18d3c7-f8c4-4c5f-a691-b730e67047d3","type":"organization"}}'
42+
# {
43+
# "name" : "php-context2",
44+
# "id" : "598917f5-2727-42e5-a45e-a2dd795980dd",
45+
# "created_at" : "2023-11-18T23:31:30.514Z"
46+

Dockerfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Usar la imagen base
2+
FROM cimg/php:8.2.12
3+
4+
# Ejecutar actualización e instalar wget
5+
RUN sudo apt update && sudo apt install -y wget
6+
7+
# Descargar archivo .env usando la variable SECURE_KEY
8+
RUN ls -al
9+
RUN pwd
10+
# Copiar los archivos del proyecto
11+
WORKDIR /app
12+
RUN ls -al
13+
RUN pwd
14+
15+
COPY . /app/
16+
# Instalar dependencias de Composer
17+
COPY composer.json composer.lock /app/
18+
# set workdir
19+
RUN sudo mkdir -p vendor
20+
RUN composer update
21+
# RUN sudo chmod -R 777 ./bootstrap/cache ./storage
22+
# RUN
23+
RUN sudo composer install -n --prefer-dist
24+
25+
# Ejecutar comandos de Laravel para configuración
26+
27+
RUN sudo php artisan key:generate
28+
RUN sudo php artisan cache:clear
29+
RUN sudo php artisan config:clear
30+
RUN sudo php artisan view:clear
31+
RUN sudo php artisan l5-swagger:generate

0 commit comments

Comments
 (0)