diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..eed91c0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,28 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +.git +.github +Dockerfile +helm diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..0ab22fb --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,68 @@ +name: Build Docker image + +on: + push: + paths-ignore: + - '**.md' + branches: + - main + - 'release/*' + tags: + - 'v*' + pull_request: + branches: + - main + +defaults: + run: + shell: bash + +jobs: + docker: + runs-on: ubuntu-20.04 + env: + DOCKER_REGISTRY_URL: tip-tip-wlan-cloud-ucentral.jfrog.io + DOCKER_REGISTRY_USERNAME: ucentral + steps: + - uses: actions/checkout@v2 + + - name: Build Docker image + run: docker build -t owls-ui:${{ github.sha }} . + + - name: Tag Docker image + run: | + TAGS="${{ github.sha }}" + + if [[ ${GITHUB_REF} == "refs/heads/"* ]] + then + CURRENT_TAG=$(echo ${GITHUB_REF#refs/heads/} | tr '/' '-') + TAGS="$TAGS $CURRENT_TAG" + else + if [[ ${GITHUB_REF} == "refs/tags/"* ]] + then + CURRENT_TAG=$(echo ${GITHUB_REF#refs/tags/} | tr '/' '-') + TAGS="$TAGS $CURRENT_TAG" + else # PR build + CURRENT_TAG=$(echo ${GITHUB_HEAD_REF#refs/heads/} | tr '/' '-') + TAGS="$TAGS $CURRENT_TAG" + fi + fi + + echo "Result tags: $TAGS" + + for tag in $TAGS; do + docker tag owls-ui:${{ github.sha }} ${{ env.DOCKER_REGISTRY_URL }}/owls-ui:$tag + done + + - name: Log into Docker registry + if: startsWith(github.ref, 'refs/tags/') || startsWith(github.ref, 'refs/pull/') || github.ref == 'refs/heads/main' + uses: docker/login-action@v1 + with: + registry: ${{ env.DOCKER_REGISTRY_URL }} + username: ${{ env.DOCKER_REGISTRY_USERNAME }} + password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }} + + - name: Push Docker images + if: startsWith(github.ref, 'refs/tags/') || startsWith(github.ref, 'refs/pull/') || github.ref == 'refs/heads/main' + run: | + docker images | grep ${{ env.DOCKER_REGISTRY_URL }}/owls-ui | awk -F ' ' '{print $1":"$2}' | xargs -I {} docker push {} diff --git a/.github/workflows/cleanup.yml b/.github/workflows/cleanup.yml new file mode 100644 index 0000000..a340621 --- /dev/null +++ b/.github/workflows/cleanup.yml @@ -0,0 +1,19 @@ +name: Clean up PR Docker images + +on: + pull_request: + branches: + - main + types: [ closed ] + +defaults: + run: + shell: bash + +jobs: + cleanup: + runs-on: ubuntu-latest + steps: + - run: | + export PR_BRANCH_TAG=$(echo ${GITHUB_HEAD_REF#refs/heads/} | tr '/' '-') + curl -uucentral:${{ secrets.DOCKER_REGISTRY_PASSWORD }} -X DELETE "https://tip.jfrog.io/artifactory/tip-wlan-cloud-ucentral/owls-ui/$PR_BRANCH_TAG" diff --git a/.github/workflows/enforce-jira-issue-key.yml b/.github/workflows/enforce-jira-issue-key.yml new file mode 100644 index 0000000..0908476 --- /dev/null +++ b/.github/workflows/enforce-jira-issue-key.yml @@ -0,0 +1,24 @@ +name: Ensure Jira issue is linked + +on: + pull_request: + types: [opened, edited, reopened, synchronize] + branches: + - 'release/*' + +jobs: + check_for_issue_key: + runs-on: ubuntu-latest + steps: + - name: Checkout actions repo + uses: actions/checkout@v2 + with: + repository: Telecominfraproject/.github + path: github + + - name: Run JIRA check + uses: ./github/composite-actions/enforce-jira-issue-key + with: + jira_base_url: ${{ secrets.TIP_JIRA_URL }} + jira_user_email: ${{ secrets.TIP_JIRA_USER_EMAIL }} + jira_api_token: ${{ secrets.TIP_JIRA_API_TOKEN }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5c6be4a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM node:14-alpine3.14 AS build +COPY package.json package-lock.json / +COPY . . +RUN npm install +RUN npm run build + +FROM nginx:1.21.4-alpine AS runtime +COPY --from=build /build/ /usr/share/nginx/html/ +COPY --from=build docker-entrypoint.d/40-generate-config.sh /docker-entrypoint.d/40-generate-config.sh diff --git a/docker-entrypoint.d/40-generate-config.sh b/docker-entrypoint.d/40-generate-config.sh new file mode 100755 index 0000000..220a72a --- /dev/null +++ b/docker-entrypoint.d/40-generate-config.sh @@ -0,0 +1,6 @@ +#!/bin/ash +# Check if variables are set +export DEFAULT_UCENTRALSEC_URL="${DEFAULT_UCENTRALSEC_URL:-https://localhost:16001}" +export ALLOW_UCENTRALSEC_CHANGE="${ALLOW_UCENTRALSEC_CHANGE:-false}" + +echo '{"DEFAULT_UCENTRALSEC_URL": "'$DEFAULT_UCENTRALSEC_URL'","ALLOW_UCENTRALSEC_CHANGE": '$ALLOW_UCENTRALSEC_CHANGE'}' > /usr/share/nginx/html/config.json