Skip to content

Commit

Permalink
Merge pull request #94 from reactivemanifesto/github-actions
Browse files Browse the repository at this point in the history
Github Actions
  • Loading branch information
JustinPihony authored Oct 15, 2024
2 parents caedd99 + cd4e76f commit 496886e
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 1 deletion.
91 changes: 91 additions & 0 deletions .github/workflows/publisher.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: PublishWorkflow

on:
push:
branches:
- master

env:
JAVA_OPTS: '-Dhttps.protocols=TLSv1.2'
DOCKER_REPOSITORY: 'docker.cloudsmith.io/lightbend/internal-registry'

jobs:
publish:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
cache: 'sbt'

- name: Build
run: |
sbt -J-Xms4G -J-Xmx4096M -J-Xss16M -Dakka.test.timefactor=4 clean test docker:publishLocal | tee build.log
perl -ne 'print "$1\n" if /\[info\] Built image .* with tags \[([^,]+)/' "build.log"
UNIQUE_VERSION=$(grep 'Built image' build.log | sed -n 's/.*with tags \[\([^,]*\),.*/\1/p')
echo "UNIQUE_VERSION=$UNIQUE_VERSION" >> $GITHUB_ENV
- name: Log in to Cloudsmith Docker registry
uses: docker/login-action@v2
with:
registry: docker.cloudsmith.io
username: ${{ secrets.CLOUDSMITH_MACHINE_USER }}
password: ${{ secrets.CLOUDSMITH_MACHINE_PASSWORD }}

- name: Tag Docker image
run: docker tag docker.cloudsmith.io/lightbend/internal-registry/reactivemanifesto-website:${{ env.UNIQUE_VERSION }} docker.cloudsmith.io/lightbend/internal-registry/reactivemanifesto-website:${{ env.UNIQUE_VERSION }}

- name: Push Docker image
run: docker push docker.cloudsmith.io/lightbend/internal-registry/reactivemanifesto-website:${{ env.UNIQUE_VERSION }}

- name: Log out of Cloudsmith Docker registry
run: docker logout docker.cloudsmith.io

- name: Set up Google Cloud SDK
uses: google-github-actions/setup-gcloud@v1
with:
version: 'latest'

- name: Install gke-gcloud-auth-plugin
run: |
gcloud components install gke-gcloud-auth-plugin
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.GCP_LIGHTBEND_INFRASTRUCTURE_CREDS }}

- name: Configure Docker for gcloud
run: gcloud auth configure-docker

- name: Get Kubernetes credentials
run: gcloud container clusters get-credentials infra-east4 --region us-east4 --project lightbend-infrastructure

- name: Update Kubernetes deployment image
run: |
kubectl set image deployment/reactivemanifesto-website reactivemanifesto-website=docker.cloudsmith.io/lightbend/internal-registry/reactivemanifesto-website:${{ env.UNIQUE_VERSION }} --namespace reactivemanifesto-website
- name: Verify Deployment
run: kubectl rollout status deployment/reactivemanifesto-website --namespace reactivemanifesto-website

- name: Email on failure
if: ${{ failure() }}
uses: dawidd6/action-send-mail@6063705cefe50cb915fc53bb06d4049cae2953b2
with:
server_address: smtp.gmail.com
server_port: 465
secure: true
username: ${{secrets.MAIL_USERNAME}}
password: ${{secrets.MAIL_PASSWORD}}
subject: "Failed: ${{ github.workflow }} / ${{ github.job }}"
to: ${{secrets.MAIL_SEND_TO}}
from: Internal IT
body: |
Job ${{ github.job }} in workflow ${{ github.workflow }} of ${{github.repository}} failed!
https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}
8 changes: 7 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ javaOptions in Universal ++= Seq(
"-Dpidfile.path=/dev/null"
)

lazy val gitSha: String = Process("git rev-parse --short HEAD").!!.trim
lazy val currentDate: String = new SimpleDateFormat("yyyyMMdd-HHmm").format(new Date())
lazy val uniqueTag: String = s"$currentDate-$gitSha"

packageName in Docker := name.value
version in Docker := "latest"
version in Docker := uniqueTag
dockerPermissionStrategy := DockerPermissionStrategy.Run
dockerRepository := sys.env.get("DOCKER_REPOSITORY").orElse(Some("docker.cloudsmith.io/lightbend/internal-registry"))
dockerCommands ++= Seq(
Expand All @@ -42,3 +46,5 @@ dockerCommands ++= Seq(
ExecCmd("RUN", "wget", "-o-", "https://downloads.mongodb.com/compass/mongodb-mongosh_1.10.6_amd64.deb"),
ExecCmd("RUN", "dpkg", "-i", "mongodb-mongosh_1.10.6_amd64.deb")
)

dockerAliases ++= Seq(dockerAlias.value.withTag(Option("latest")))

0 comments on commit 496886e

Please sign in to comment.