From ea896fb7134775f613a82d36683d0533e6a52582 Mon Sep 17 00:00:00 2001 From: Dave Gallant Date: Sun, 25 Dec 2022 12:09:07 -0500 Subject: [PATCH] Add publish-containers workflow --- .github/dependabot.yml | 32 ++++----- .github/workflows/publish-containers.yml | 83 ++++++++++++++++++++++++ Makefile | 9 ++- README.md | 12 +++- docker-compose.prod.yml | 16 +++++ 5 files changed, 132 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/publish-containers.yml create mode 100644 docker-compose.prod.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 414b8c0..9013041 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -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 diff --git a/.github/workflows/publish-containers.yml b/.github/workflows/publish-containers.yml new file mode 100644 index 0000000..8f4f2e5 --- /dev/null +++ b/.github/workflows/publish-containers.yml @@ -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 }} diff --git a/Makefile b/Makefile index 4be02ff..3105e7b 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index 597c331..ff06e14 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml new file mode 100644 index 0000000..84adf5a --- /dev/null +++ b/docker-compose.prod.yml @@ -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