Skip to content

Commit

Permalink
ci: release athens,nginx docker image and docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva committed Sep 28, 2021
1 parent 10e857f commit 2ed4f71
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 41 deletions.
92 changes: 62 additions & 30 deletions .github/workflows/build.yml
Expand Up @@ -12,7 +12,6 @@ on:

env:
REGISTRY: ghcr.io # Github container registry https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry
IMAGE_NAME: ${{ github.repository }}

jobs:

Expand Down Expand Up @@ -209,51 +208,84 @@ jobs:
if: matrix.os == 'ubuntu-latest'
run: lein uberjar

- name: Publish server JAR
if: matrix.os == 'ubuntu-latest'
uses: ncipollo/release-action@v1
with:
artifacts: "target/athens-lan-party-standalone.jar"
token: ${{ secrets.github_token }}
allowUpdates: true
prerelease: true
draft: true


release-server:
runs-on: ubuntu-latest
needs: [test, lint, style, carve]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')

steps:
- name: Git checkout
uses: actions/checkout@v1
with:
fetch-depth: 1
submodules: 'true'

- uses: ./.github/custom-actions/clojure-env

- name: Build server JAR
run: lein uberjar

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

- name: Login to Github Container registry
uses: docker/login-action@v1
# You may need to manage write and read access of (GitHub Actions for repositories) [https://docs.github.com/en/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions#upgrading-a-workflow-that-accesses-ghcrio]
# in the container settings.
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
- name: Extract server metadata (tags, labels) for athens docker image
id: athens-meta
uses: docker/metadata-action@v3
with:
images: ${{ env.REGISTRY }}/${{ github.repository }}

- name: Extract server metadata (tags, labels) for nginx docker image
id: nginx-meta
uses: docker/metadata-action@v3
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
images: ${{ env.REGISTRY }}/${{ github.repository }}-nginx

- name: Build and push athens
uses: docker/build-push-action@v2
with:
# Use the current folder as context instead of the branch.
# Needed to use artifacts like the server jar.
context: .
file: athens.dockerfile
push: true
tags: ${{ steps.athens-meta.outputs.tags }}
labels: ${{ steps.athens-meta.outputs.labels }}
# Use GitHub actions cache.
# https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md#github-cache
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Build and push nginx
uses: docker/build-push-action@v2
with:
context: .
file: nginx.dockerfile
push: true
tags: ${{ steps.nginx-meta.outputs.tags }}
labels: ${{ steps.nginx-meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max


- name: Build and Push
uses: docker/build-push-action@v2 # https://github.com/docker/build-push-action
- name: Replace version in docker-compose
run: sed -i.bk 's/:latest/:${{ steps.athens-meta.outputs.version }}/' docker-compose.yml

# By default, this action uses the Git context so you don't need to use the
# actions/checkout action The git reference will be based on the event that
# triggered your workflow and will result in the following context:
# https://github.com/<owner>/<repo>.git#<ref>.
- name: Publish Docker compose
uses: ncipollo/release-action@v1
with:
push: true # Will automatically push the build result to registry.
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# file: .github/workflow/Dockerfile # Path to the Dockerfile. (default {context}/Dockerfile)
# cache-to: # Export build cache to an external cache destination.
# cache-from: # Use an external cache source for a build. Supported types are registry, local and gha.
# can use cache from previously exported with --cache-to.
# build-args: # List of build time variables
artifacts: "docker-compose.yml"
token: ${{ secrets.GITHUB_TOKEN }}
allowUpdates: true
prerelease: true
draft: true



5 changes: 4 additions & 1 deletion .gitignore
Expand Up @@ -34,4 +34,7 @@ dist

# design system static build
/storybook-static
/src/gen
/src/gen

# docker compose templating backup
docker-compose.yml.bk
31 changes: 31 additions & 0 deletions README.self-hosted.md
Expand Up @@ -79,3 +79,34 @@ After starting HTTP & nREPL servers are running on default ports or changes in `
Stop the Self-Hosted server. [ctrl+c] if using `lein run` or [ctrl+d] if repl.
By default Datahike DB is stored in `/tmp/exmaple`, remove this forlder
start the srever and Bob's your unkle.


## Docker

You can create an Athens server without installing anything else via docker compose.

Pick a [release](https://github.com/athensresearch/athens/releases you'd like to use, download the `docker-compose.yml` file in the release to a folder, and then run `docker compose up --no-build`.

For example, for `v1.0.0-alpha.rtc.11`:

```sh
curl https://github.com/athensresearch/athens/releases/download/v1.0.0-alpha.rtc.11/docker-compose.yml --output docker-compose.yml
docker compose up --no-build
```

The server will be acessible at `localhost:80`.

You can override the configuration via an environment variable:

```sh
config_edn="{:password \"YourServerPassword\" :datahike {:store {:path \"/srv/athens/db\"}}}" docker compose up --no-build
```

or via an `.env` file located in the same directory as the downloaded `docker-compose.yml`:

```sh
# .env
config_edn="{:password \"YourServerPassword\" :datahike {:store {:path \"/srv/athens/db\"}}}"
```


File renamed without changes.
22 changes: 13 additions & 9 deletions docker-compose.yml
@@ -1,8 +1,10 @@
version: "3"
services:
athens-server:
build: .
image: athens-server:1.0.0-alpha.rtc.2
athens:
image: ghcr.io/athensresearch/athens:latest
build:
context: .
dockerfile: athens.dockerfile
restart: always
expose:
- 3010 # Change this according to config.edn
Expand All @@ -11,16 +13,18 @@ services:
- crash-logs:/srv/athens/logs
environment: # set environment variables
# config_edn is deep merged with the whole config file
config_edn: "{:datahike {:store {:path \"/srv/athens/db\"}}}"
- config_edn=${config_edn:-{:datahike {:store {:path "/srv/athens/db"}}}}


nginx:
image: nginx
athens-nginx:
image: ghcr.io/athensresearch/athens-nginx:latest
build:
context: .
dockerfile: nginx.dockerfile
restart: always
depends_on:
- athens-server
- athens
restart: always
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
ports:
- 80:80

Expand Down
2 changes: 1 addition & 1 deletion nginx.conf
Expand Up @@ -6,7 +6,7 @@ http {
}

upstream websocket {
server athens-server:3010; # Change the port based on config.edn
server athens:3010; # Change the port based on config.edn
}

server {
Expand Down
6 changes: 6 additions & 0 deletions nginx.dockerfile
@@ -0,0 +1,6 @@
# nginx with a custom config
FROM nginx

# Copy from local working directory
COPY ./nginx.conf /etc/nginx/nginx.conf

0 comments on commit 2ed4f71

Please sign in to comment.