Add publish-containers workflow

This commit is contained in:
Dave Gallant
2022-12-25 12:09:07 -05:00
parent 214cc13d49
commit ea896fb713
5 changed files with 132 additions and 20 deletions

View File

@@ -1,18 +1,18 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
reviewers:
- davegallant
assignees:
- davegallant
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: weekly
reviewers:
- davegallant
assignees:
- davegallant
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
reviewers:
- davegallant
assignees:
- davegallant
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: weekly
reviewers:
- davegallant
assignees:
- davegallant

View File

@@ -0,0 +1,83 @@
name: Publish Containers
on: [push]
jobs:
publish-backend:
name: Publish rfd-fyi-backend
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Prepare
id: prep
run: |
IMAGE_NAME=ghcr.io/${{ github.repository_owner }}/rfd-fyi-backend
VERSION=${GITHUB_REF##*/}
if [[ $GITHUB_REF == refs/heads/main ]]; then
VERSION=latest
fi
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
fi
TAGS="${IMAGE_NAME}:${VERSION}"
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
TAGS="$TAGS,${IMAGE_NAME}:latest"
fi
echo ::set-output name=tags::${TAGS}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Packages Docker Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push to Packages
uses: docker/build-push-action@v3
with:
context: backend
file: ./backend/Dockerfile
push: true
tags: ${{ steps.prep.outputs.tags }}
publish-frontend:
name: Publish rfd-fyi-frontend
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Prepare
id: prep
run: |
IMAGE_NAME=ghcr.io/${{ github.repository_owner }}/rfd-fyi-frontend
VERSION=${GITHUB_REF##*/}
if [[ $GITHUB_REF == refs/heads/main ]]; then
VERSION=latest
fi
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
fi
TAGS="${IMAGE_NAME}:${VERSION}"
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
TAGS="$TAGS,${IMAGE_NAME}:latest"
fi
echo ::set-output name=tags::${TAGS}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Packages Docker Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push to Packages
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.prep.outputs.tags }}

View File

@@ -23,11 +23,16 @@ frontend:
@npx vue-cli-service serve
.PHONY: server
## up: Build and run in docker compose
up:
## dev: Build and run in docker compose
dev:
docker compose up --build -d
.PHONY: up
## prod: Run the latest images in docker compose
prod:
docker compose -f docker-compose.prod.yml up -d
.PHONY: up
## teardown: Teardown docker
teardown:
docker compose down

View File

@@ -12,7 +12,7 @@ Ensure that an `.env` file is filled in with the appropriate values.
Example key/values can be found in [example.env](./example.env).
*Note: that a [honeycomb](https://honeycomb.io/) API key is currently required.*
_Note: that a [honeycomb](https://honeycomb.io/) API key is currently required._
## Local Development
@@ -32,6 +32,14 @@ make frontend
## Docker Compose
To build containers from source:
```sh
make up
make dev
```
To run the latest published images:
```sh
make prod
```

16
docker-compose.prod.yml Normal file
View File

@@ -0,0 +1,16 @@
version: "3.9"
services:
frontend:
image: ghcr.io/davegallant/rfd-fyi-frontend
ports:
- 80:80
- 443:443
links:
- "backend:backend"
volumes:
- ./data:/data
backend:
image: ghcr.io/davegallant/rfd-fyi-backend
ports:
- 8080:8080
env_file: .env