Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
CyanoFresh committed Aug 10, 2021
0 parents commit 4e66f5d
Show file tree
Hide file tree
Showing 21 changed files with 1,059 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.git
.idea
83 changes: 83 additions & 0 deletions .github/workflows/docker-compose-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Docker Build & Push on release

on:
push:
branches: [ release ]
tags: [ 'v*.*.*' ]
workflow_dispatch:

env:
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
DOCKER_BUILDKIT: 1
COMPOSE_DOCKER_CLI_BUILD: 1

jobs:
build:

runs-on: ubuntu-latest
permissions:
contents: read
packages: write

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

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

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# TODO: pull
- name: docker/build-push-action
uses: docker/build-push-action@v2
with:
context: ./app1
file: ./app1/Dockerfile
load: true
push: false
builder: ${{ steps.buildx.outputs.name }}
tags: ${{ env.REGISTRY }}/${{ github.repository }}_app1:${{ github.event.release.tag_name }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new

- name: docker/build-push-action
uses: docker/build-push-action@v2
with:
context: ./app2
file: ./app2/Dockerfile
load: true
push: false
builder: ${{ steps.buildx.outputs.name }}
tags: ${{ env.REGISTRY }}/${{ github.repository }}_app2:${{ github.event.release.tag_name }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new

- name: Build the stack
run: docker-compose build --build-arg BUILDKIT_INLINE_CACHE=1

- name: Push the stack
run: docker-compose push

- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.log
docker-compose.override.yml

# Project exclude paths
/app1/node_modules/
/app2/node_modules/
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/docker-compose-ga-cache-example.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/jsLibraryMappings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Docker Compose + Github Actions + Layers Cache
===

Example project
2 changes: 2 additions & 0 deletions app1/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
cache
12 changes: 12 additions & 0 deletions app1/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:lts-alpine

WORKDIR /opt/project

COPY package*.json ./
RUN npm ci --only=production

COPY --chown=node:node . .

USER node

CMD [ "npm", "start" ]
18 changes: 18 additions & 0 deletions app1/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const fastify = require('fastify')({
logger: true
})

fastify.get('/', async (request, reply) => {
return { hello: 'world' }
})

const start = async () => {
try {
await fastify.listen(process.env.PORT)
} catch (err) {
fastify.log.error(err)
process.exit(1)
}
}

start()
Loading

0 comments on commit 4e66f5d

Please sign in to comment.