-
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.
Showing
5 changed files
with
171 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: "build-test-pubtodockerhub" | ||
|
||
# IMPORTANT : personnalisez cette variable pour que les images | ||
# de votre application soient pousées sur dockerhub | ||
# dans le repository ayant ce nom | ||
# exemple, si vous indiquez : abesesr/item-front | ||
# alors l'image sera poussée sur https://hub.docker.com/r/abesesr/item-front | ||
env: | ||
DOCKERHUB_IMAGE_PREFIX: abesesr/item | ||
|
||
on: | ||
push: | ||
paths-ignore: | ||
- '**.md' | ||
- '.github/**' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build-test-pubtodockerhub: | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
|
||
- name: "Build: checkout source code" | ||
uses: actions/checkout@v2 | ||
- name: "Build: build docker image" | ||
run: | | ||
docker build . -t localimage:latest | ||
- name: "Push: prepare version from git tags/branchs" | ||
id: docker_tag_meta | ||
uses: docker/metadata-action@v3 | ||
with: | ||
images: ${{ env.DOCKERHUB_IMAGE_PREFIX }} | ||
- name: "Push: login to DockerHub" | ||
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags/')) | ||
run: | | ||
echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin | ||
- name: "Push: push docker image" | ||
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags/')) | ||
run: | | ||
DOCKER_TAGS="${{ steps.docker_tag_meta.outputs.tags }}" | ||
for DOCKER_TAG in $DOCKER_TAGS | ||
do | ||
# publication de l'image pour le front | ||
docker build . --target front-image -t ${DOCKER_TAG}-front | ||
docker push ${DOCKER_TAG}-front | ||
done |
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,80 @@ | ||
name: 'Create release' | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
releaseVersion: | ||
description: 'Version de la release (semver)' | ||
required: true | ||
default: 'x.x.x' | ||
snapshotVersion: | ||
description: 'Version de snapshot (semver)' | ||
required: true | ||
default: 'x.x.x-SNAPSHOT' | ||
|
||
jobs: | ||
create-release: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: 'Checkout source code' | ||
uses: 'actions/checkout@v3' | ||
with: | ||
fetch-depth: '0' # to get all the tags locally | ||
# https://stackoverflow.com/questions/67550727/push-event-doesnt-trigger-workflow-on-push-paths-github-actions | ||
token: ${{ secrets.TOKEN_GITHUB_FOR_GITHUB_ACTION }} | ||
|
||
|
||
- name: 'Verify release is created only on "main" or "master" git branch' | ||
run: | | ||
CURRENT_GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD) | ||
echo $CURRENT_GIT_BRANCH | ||
[[ "$CURRENT_GIT_BRANCH" == "main" || "$CURRENT_GIT_BRANCH" == "master" ]] && exit 0 || exit 1 | ||
- name: 'Verify version is semver formatted (X.X.X)' | ||
env: | ||
NEW_TAG: ${{ github.event.inputs.releaseVersion }} | ||
SNAPSHOT: ${{ github.event.inputs.snapshotVersion }} | ||
run: | | ||
echo $NEW_TAG | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | ||
echo $SNAPSHOT | grep -E '^[0-9]+\.[0-9]+\.[0-9]+-SNAPSHOT$' | ||
- name: 'Verify version is not already used as a git tag' | ||
env: | ||
NEW_TAG: ${{ github.event.inputs.releaseVersion }} | ||
run: | | ||
[[ "$(git tag --list | grep $NEW_TAG)" == "" ]] && exit 0 || exit 1 | ||
- name: 'Generate the new version (patch few files + git tag)' | ||
env: | ||
NEW_TAG: ${{ github.event.inputs.releaseVersion }} | ||
SNAPSHOT: ${{ github.event.inputs.snapshotVersion }} | ||
run: | | ||
# préparation de la release qui va : | ||
# - modifier le numéro de version dans le package.json du projet (et éventuellement dans le README.md ou d'autres fichiers, cf le sed) | ||
# - créer un tag git du numéro de version en question | ||
# - pousser le tout sur le dépôt github et faire la fusion avec la branche develop | ||
git config --global user.email "github-action@noreply" | ||
git config --global user.name "Github Action" | ||
npm config set tag-version-prefix '' | ||
npm config set git-tag-version false | ||
npm version $NEW_TAG | ||
sed -i "s#Version: [0-9]+\.[0-9]+\.[0-9]+#Version: $NEW_TAG#g" README.md | ||
git add . | ||
git commit -m "Version $NEW_TAG" | ||
git tag $NEW_TAG | ||
git push origin $NEW_TAG | ||
git commit --amend -m "Version $NEW_TAG [skip ci]" | ||
git push | ||
# merge la préparation de la nouvelle version sur develop | ||
# (version X.X.X-SNAPSHOT) | ||
git switch develop | ||
git merge main -m "Merge main to develop [skip ci]" | ||
npm version $SNAPSHOT | ||
sed -i "s#Version: [0-9]+\.[0-9]+\.[0-9]+#Version: $SNAPSHOT#g" README.md | ||
git add . | ||
git commit -m "Version $SNAPSHOT [skip ci]" | ||
git push | ||
- name: 'Create the github release' | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
tag_name: ${{ github.event.inputs.releaseVersion }} | ||
generate_release_notes: true | ||
token: ${{ secrets.TOKEN_GITHUB_FOR_GITHUB_ACTION }} |
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,20 @@ | ||
#!/bin/bash | ||
|
||
# Paramètres par défaut du conteneur | ||
export ITEM_FRONT_API_BASEURL=${ITEM_FRONT_API_BASEURL:='http://localhost:8081/'} | ||
|
||
|
||
# Remplace les placeholders dans le code généré en prod | ||
# ITEM_PLACEHOLDER_VUE_APP_ROOT_API | ||
# On va remplacer les placeholders depuis les JS originales | ||
echo "-> Remplacement des placeholders venant du .env de vuejs dans la destination /usr/share/nginx/html/" | ||
echo "-> ITEM_FRONT_API_BASEURL=${ITEM_FRONT_API_BASEURL}" | ||
rm -rf /usr/share/nginx/html/ | ||
cp -rf /usr/share/nginx/html.orig/ /usr/share/nginx/html/ | ||
sed -i \ | ||
"s#ITEM_PLACEHOLDER_VITE_API_URL#${ITEM_FRONT_API_BASEURL}#g" \ | ||
/usr/share/nginx/html/js/* | ||
|
||
|
||
# execute nginx (cf CMD dans Dockerfile) | ||
exec "$@" |
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,19 @@ | ||
# active gzip sur les retours des requetes http | ||
# pour optimiser les perf pour les chargements | ||
# initiaux des pages de l'appli | ||
gzip on; | ||
gzip_types *; | ||
|
||
server { | ||
listen 80; | ||
server_name localhost; | ||
|
||
# subtilité pour vuejs | ||
# toutes les URL doivent charger la même page | ||
# https://zestedesavoir.com/forums/sujet/15137/docker-nginx-et-vuejs-avec-un-prefix/ | ||
location / { | ||
root /usr/share/nginx/html; | ||
index index.html; | ||
try_files $uri $uri/ /index.html?$args; | ||
} | ||
} |
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,5 @@ | ||
# .env pour vuejs qui permet de positionner un placeholder | ||
# à la place de l'URL de l'API de item-api | ||
# pour injecter une URL de l'API au moment de la création du conteneur | ||
# et éviter ainsi d'avoir une URL de l'API en static dans l'image docker | ||
VITE_API_URL=ITEM_PLACEHOLDER_VUE_APP_ROOT_API |