From ae364338769d264e56b564603530a7905c4177df Mon Sep 17 00:00:00 2001 From: Johann Hoffmann Date: Tue, 12 Oct 2021 16:27:36 +0200 Subject: [PATCH] Add Dockerfile and Github workflows Signed-off-by: Johann Hoffmann --- .dockerignore | 28 ++++++++++ .github/workflows/ci.yml | 68 +++++++++++++++++++++++ .github/workflows/cleanup.yml | 19 +++++++ Dockerfile | 9 +++ docker-entrypoint.d/40-generate-config.sh | 6 ++ 5 files changed, 130 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/cleanup.yml create mode 100644 Dockerfile create mode 100755 docker-entrypoint.d/40-generate-config.sh 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..42ccc61 --- /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 owprov-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 owprov-ui:${{ github.sha }} ${{ env.DOCKER_REGISTRY_URL }}/owprov-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 }}/owprov-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..65bf6d4 --- /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/owprov-ui/$PR_BRANCH_TAG" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..820ba77 --- /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.3-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