Skip to content

Commit

Permalink
reogranise build actions for docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
fredex42 committed Dec 19, 2023
1 parent eb87f64 commit 5840668
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 24 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/concierge-graphql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Build and upload

on:
push:
branches: ["*"]
workflow_dispatch: {}

jobs:
concierge-graphql:
runs-on: ubuntu-latest

# The first two permissions are needed to interact with GitHub's OIDC Token endpoint.
# The second set of three permissions are needed to write test results back to GH
permissions:
id-token: write
contents: read
issues: read
checks: write
packages: write
pull-requests: write

steps:
- uses: actions/checkout@v2

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

- name: Setup JDK
uses: actions/setup-java@v3
with:
distribution: corretto
java-version: 17
cache: sbt

- name: Build and test
env:
SBT_JUNIT_OUTPUT: ./junit-tests
JAVA_OPTS: -Dsbt.log.noformat=true
BUILD_NUMBER: ${{ github.run_number }}
run: |
sbt 'test;docker:publishLocal'
- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
if: always() #runs even if there is a test failure
with:
files: junit-tests/*.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Build and upload

on:
push:
branchs: ["main"]
workflow_dispatch: {}
#on:
# push:
# branchs: ["main"]
# workflow_dispatch: {}

jobs:
concierge-graphql:
Expand Down
48 changes: 48 additions & 0 deletions .github/workflows/graphiql-explorer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: GraphiQL explorer

on:
push:
branches: ["*"]
workflow_dispatch: {}

jobs:
concierge-graphql:
runs-on: ubuntu-latest

# The first two permissions are needed to interact with GitHub's OIDC Token endpoint.
# The second set of three permissions are needed to write test results back to GH
permissions:
id-token: write
contents: read
issues: read
checks: write
packages: write
pull-requests: write

steps:
- uses: actions/checkout@v2

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

- uses: actions/setup-node@v3
with:
node-version: 18.x
cache: 'yarn'
cache-dependency-path: explorer/yarn.lock

- run: yarn install --frozen-lockfile
name: Prepare to build explorer
working-directory: explorer

- run: yarn build
name: Build explorer
working-directory: explorer


- name: Build and push
uses: docker/build-push-action@v5
working-directory: explorer
with:
push: true
tags: ghcr.io/guardian/concierge-graphql/graphiql-explorer:${{ github.run_number }}
18 changes: 0 additions & 18 deletions .github/workflows/snyk.yml

This file was deleted.

29 changes: 28 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
enablePlugins(DebianPlugin, JavaServerAppPackaging, SystemdPlugin, DockerPlugin, AshScriptPlugin)

import scala.sys.process._
import com.typesafe.sbt.packager.docker
ThisBuild / version := "0.1.0"

ThisBuild / scalaVersion := "2.13.11"
Expand All @@ -11,10 +12,36 @@ packageSummary := "A proof-of-concept for doing CAPI queries with GraphQL"

val prometheusVersion = "0.16.0"

lazy val ensureDockerBuildx = taskKey[Unit]("Ensure that docker buildx configuration exists")
lazy val dockerBuildWithBuildx = taskKey[Unit]("Build docker images using buildx")
lazy val dockerBuildxSettings = Seq(
ensureDockerBuildx := {
if (Process("docker buildx inspect multi-arch-builder").! == 1) {
Process("docker buildx create --use --name multi-arch-builder", baseDirectory.value).!
}
},
dockerBuildWithBuildx := {
streams.value.log("Building and pushing image with Buildx")
dockerAliases.value.foreach(
alias => Process("docker buildx build --platform=linux/arm64,linux/amd64 --push -t " +
alias + " .", baseDirectory.value / "target" / "docker"/ "stage").!
)
},
publish in Docker := Def.sequential(
publishLocal in Docker,
ensureDockerBuildx,
dockerBuildWithBuildx
).value
)

lazy val root = (project in file("."))
.settings(
dockerBuildxSettings,
name := "concierge-graphql",
dockerBaseImage := "amazoncorretto:17-alpine",
dockerRepository := Some("ghcr.io/guardian/concierge-graphql"),
dockerAliases := Seq(docker.DockerAlias(registryHost=dockerRepository.value, username=None, name="concierge-graphql", tag=Some(sys.env.getOrElse("BUILD_NUMBER", "DEV")))),
dockerExposedPorts := Seq(9000),
libraryDependencies ++= Seq(
"org.http4s" %% "http4s-core" % "0.23.21",
"org.http4s" %% "http4s-dsl" % "0.23.21",
Expand Down
3 changes: 3 additions & 0 deletions explorer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM nginx:mainline-alpine

COPY build/* /usr/share/nginx/html
9 changes: 9 additions & 0 deletions explorer/buildit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

if [ -d build/ ]; then
rm -rf build
fi

yarn --frozen-lockfile
yarn run build
docker build . -t graphiql-explorer:DEV
2 changes: 1 addition & 1 deletion explorer/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ReactDOM from 'react-dom';

import 'graphiql/graphiql.css';

const fetcher = createGraphiQLFetcher({ url: 'http://concierge-graphql.test:8000/query', headers: {'X-Consumer-Username': ":internal"} });
const fetcher = createGraphiQLFetcher({ url: "/query", headers: {'X-Consumer-Username': ":internal"} });

const rootElem = document.createElement('div');
rootElem.setAttribute("style","height: 100vh");
Expand Down

0 comments on commit 5840668

Please sign in to comment.