Skip to content

Commit

Permalink
feat(CI): allow configurable timed host
Browse files Browse the repository at this point in the history
  • Loading branch information
Akanksh Saxena authored and velrest committed Dec 10, 2021
1 parent 2cc8202 commit c233c73
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 75 deletions.
69 changes: 2 additions & 67 deletions .github/workflows/release-container-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,73 +10,6 @@ on:
- 'v*.*.*'

jobs:
backend:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Prepare Image Metadata
id: prep
run: |
DOCKER_IMAGE=ghcr.io/adfinis-sygroup/customer-center/backend
VERSION=noop
if [ "${{ github.event_name }}" = "schedule" ]; then
VERSION=nightly
elif [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/heads/* ]]; then
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then
VERSION=edge
fi
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.number }}
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
MINOR=${VERSION%.*}
MAJOR=${MINOR%.*}
TAGS="$TAGS,${DOCKER_IMAGE}:${MINOR},${DOCKER_IMAGE}:${MAJOR},${DOCKER_IMAGE}:latest"
elif [ "${{ github.event_name }}" = "push" ]; then
TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
fi
echo ::set-output name=version::${VERSION}
echo ::set-output name=tags::${TAGS}
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
- name: Login to GHCR
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
if: ${{ github.event_name != 'pull_request' }}

- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: ./backend
file: ./backend/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.prep.outputs.tags }}
labels: |
org.opencontainers.image.title=${{ github.event.repository.name }}
org.opencontainers.image.description=${{ github.event.repository.description }}
org.opencontainers.image.url=${{ github.event.repository.html_url }}
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
org.opencontainers.image.version=${{ steps.prep.outputs.version }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }}
frontend:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -135,6 +68,8 @@ jobs:
build-args: |
AUTH_ROLE_ADMIN=${{ secrets.AUTH_ROLE_ADMIN }}
AUTH_ROLE_EMPLOYEE=${{ secrets.AUTH_ROLE_EMPLOYEE }}
TIMED_STAGING_HOST=${{ secrets.TIMED_STAGING_HOST }}
TIMED_PROD_HOST=${{ secrets.TIMED_PROD_HOST }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.prep.outputs.tags }}
labels: |
Expand Down
4 changes: 4 additions & 0 deletions frontend/app/adapters/application.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import JSONAPIAdapter from "@ember-data/adapter/json-api";
import ENV from "customer-center/config/environment";
import OIDCAdapterMixin from "ember-simple-auth-oidc/mixins/oidc-adapter-mixin";

const BaseAdapter = JSONAPIAdapter.extend(OIDCAdapterMixin);

export default class ApplicationAdapter extends BaseAdapter {
namespace = "api/v1";
host = window.location.host.includes("test")
? ENV.APP.hostStaging
: ENV.APP.hostProd;
}
17 changes: 11 additions & 6 deletions frontend/app/services/account.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getOwner } from "@ember/application";
import { reads } from "@ember/object/computed";
import Service, { inject as service } from "@ember/service";
import { tracked } from "@glimmer/tracking";
Expand Down Expand Up @@ -31,12 +32,16 @@ export default class AccountService extends Service {

async fetchCurrentUser() {
try {
const response = await fetch("/api/v1/users/me", {
method: "GET",
headers: {
Authorization: `Bearer ${this.accessToken}`,
},
});
const adapter = getOwner(this).lookup("adapter:application");
const response = await fetch(
`${adapter.host}/${adapter.namespace}/users/me`,
{
method: "GET",
headers: {
Authorization: `Bearer ${this.accessToken}`,
},
}
);

const json = await response.json();
const { id } = json.data;
Expand Down
4 changes: 2 additions & 2 deletions frontend/config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ module.exports = function (environment) {
},

APP: {
loginRoute: "account.login",

hostStaging: env("TIMED_STAGING_HOST", "http://localhost:8000"),
hostProd: env("TIMED_PROD_HOST", "http://localhost:8000"),
// Define alertTime in hours.
// When total time comes close to alertTime, text color changes.
alertTime: 5,
Expand Down

0 comments on commit c233c73

Please sign in to comment.