Skip to content

Commit

Permalink
new ci & workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
MickaelMenet committed Apr 18, 2024
1 parent 03d6481 commit 250407b
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 56 deletions.
116 changes: 71 additions & 45 deletions .github/workflows/ci-sonorV2.yml
Original file line number Diff line number Diff line change
@@ -1,78 +1,104 @@
name: Release & Docker
name: sonorV2 Branch CI - Build release candidate

on:
push:
branches:
- sonorV2

jobs:
install:
check-version:
runs-on: ubuntu-latest
outputs:
release-version: ${{ steps.version.outputs.pe-version }}
tag-already-exists: ${{ steps.checkTag.outputs.exists }}
steps:
- name: Use Node.js 14C
uses: actions/setup-node@v1
- name: Checkout
uses: actions/checkout@v4

- name: Get version
id: version
run: echo "pe-version=$(cat package.json | jq -r '.version')-experimental" >> $GITHUB_OUTPUT

- name: Print version
run: echo ${{ steps.version.outputs.pe-version }}

- uses: mukunku/[email protected]
id: checkTag
with:
node-version: 18
- run: yarn --frozen-lockfile
build:
tag: ${{ steps.version.outputs.pe-version }}

- if: ${{ steps.checkTag.outputs.exists == 'true' }}
name: "Skip release"
run: echo "Nothing to tag/release, the release ${{ steps.version.outputs.pe-version }} already exists"

create-release:
needs: check-version
runs-on: ubuntu-latest
if: ${{ needs.check-version.outputs.tag-already-exists == 'false' }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
fetch-depth: 0

- name: Get previous tag
id: previousTag
run: echo "previousTag=$(git --no-pager tag --sort=creatordate --merged ${{ github.ref_name }} | grep '^[0-9]\+\.[0-9]\+\.[0-9]\+\-experimental$' | tail -1)" >> $GITHUB_OUTPUT

- uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.check-version.outputs.release-version }}
target_commitish: ${{ github.head_ref || github.ref }}
name: ${{ needs.check-version.outputs.release-version }}
body: ${{steps.changelog.outputs.changes}}
prerelease: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build-release:
needs: create-release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Extract branch name
shell: bash
run: echo "branch=$(echo ${GITHUB_REF#refs/heads/})" >>$GITHUB_OUTPUT
id: extract_branch

- uses: actions/checkout@v4
with:
ref: ${{ steps.extract_branch.outputs.branch }}

- name: Use Node.js 18
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: 18
- run: yarn
- run: yarn build

- name: Upload build
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: build
path: dist
release:
runs-on: ubuntu-latest
steps:
- name: Checkout current branch
uses: actions/checkout@v2
- name: Get current version
id: version
uses: notiz-dev/github-action-json-property@release
with:
path: "package.json"
prop_path: "version"
- run: echo ${{steps.version.outputs.prop}}
- name: Release snapshot
id: release-snapshot
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{steps.version.outputs.prop}}
release_name: ${{steps.version.outputs.prop}}
draft: false
prerelease: false
docker:
needs: build
needs:
- check-version
- build-release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Download build
id: download
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
name: build
path: dist
- name: Get current version
id: version
uses: notiz-dev/github-action-json-property@release
with:
path: "package.json"
prop_path: "version"
- run: echo ${{steps.version.outputs.prop}}

- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@master
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: inseefr/pearl-jam
name: inseefr/sonor
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
tags: ${{steps.version.outputs.prop}}
tags: "latest, ${{ needs.check-version.outputs.release-version }}"
35 changes: 27 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
FROM nginx
FROM nginx:stable-alpine

## Remove default nginx index page
RUN rm -rf /usr/share/nginx/html/*

#Add build to nginx root webapp
ADD dist /usr/share/nginx/html

#Copy nginx configuration
RUN rm etc/nginx/conf.d/default.conf
# Overload nginx.conf to enable cors
COPY nginx.conf etc/nginx/conf.d/
COPY container/nginx.conf etc/nginx/conf.d/


# Copy .env file and shell script to container
WORKDIR /usr/share/nginx/html
COPY ./scripts/env.sh .
COPY .env .

# Make shell script executable
# Add bash
RUN apk add --no-cache bash

COPY scripts/env.sh .
COPY scripts/.env .

# Make our shell script executable
RUN chmod +x env.sh

# add non-root user
RUN touch /var/run/nginx.pid
RUN chown -R nginx:nginx /var/run/nginx.pid /usr/share/nginx/html /var/cache/nginx /var/log/nginx /etc/nginx/conf.d

# non root users cannot listen on 80
EXPOSE 8080

USER nginx

# Start Nginx server
CMD ["/bin/bash", "-c", "/usr/share/nginx/html/env.sh && nginx -g \"daemon off;\""]
ENTRYPOINT bash -c "/usr/share/nginx/html/env.sh && nginx -g 'daemon off;'"
2 changes: 1 addition & 1 deletion nginx.conf → container/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
server {
listen 80 default_server;
listen 8080;
server_name /usr/share/nginx/html;

root /usr/share/nginx/html;
Expand Down
5 changes: 5 additions & 0 deletions scripts/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
VITE_API_ENDPOINT=https://localhost:8080
VITE_AUTH_TYPE=oidc
VITE_OIDC_CLIENT_ID=localhost-frontend
VITE_OIDC_ISSUER=https://localhost:8080
VITE_LOCALE=fr
6 changes: 4 additions & 2 deletions scripts/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ do
# Otherwise use value from .env file
[[ -z $value ]] && value=${varvalue}

export $varname=$value
export $varname=$value

done < .env
envsubst < "./configuration.json" > "configuration.temp"
mv configuration.temp configuration.json
envsubst < "./keycloak.json" > "keycloak.temp"
mv configuration.temp configuration.json
mv keycloak.temp keycloak.json

0 comments on commit 250407b

Please sign in to comment.