Last active
October 30, 2022 05:05
-
-
Save airtonix/701fe9f898554a00b6be609941ef5210 to your computer and use it in GitHub Desktop.
Github Workflow to Publish OCI Docker Image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: ci | |
# https://github.com/docker/build-push-action/blob/master/docs/advanced/tags-labels.md | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
on: | |
schedule: | |
- cron: '0 10 * * *' | |
push: | |
branches: | |
- '**' | |
tags: | |
- 'v*.*.*' | |
pull_request: | |
branches: | |
- 'master' | |
jobs: | |
Test: | |
runs-on: ubuntu-latest | |
# only run this job on PR | |
if: github.event_name == 'pull_request' | |
steps: | |
- uses: actions/checkout@v3 | |
# Minimal required ENVVARS for smoketest | |
- name: Create Test ENVVARS | |
run: | | |
echo """ | |
MONGODB_URL=mongodb://mongo:27017/personal-drive | |
KEY=super-secrete-server-encryption-key | |
REMOTE_URL=http://localhost:3000/ | |
DB_TYPE=mongo | |
FS_DIRECTORY=/store | |
PASSWORD=super-secrete-password | |
SSL=false | |
DISABLE_STORAGE=true | |
DOCKER=true | |
NODE_ENV=production | |
PORT=3000 | |
HTTP_PORT=3000 | |
HTTPS_PORT=8080""" > ./docker-variables.env | |
- name: Build image | |
run: docker-compose build | |
# Create required external mongo data volue | |
- name: Create Mongo Volume | |
run: docker volume create mongodb_data_volume | |
- name: Booting up MongoDB | |
run: docker-compose up -d mongo | |
- name: Running indexes creation | |
run: docker-compose run app npm run create-indexes-database | |
Release: | |
runs-on: ubuntu-latest | |
needs: Test | |
# | |
# https://github.com/benjamin-bergia/github-workflow-patterns | |
# | |
# Always run : but only if | |
# Test Job was skipped, | |
# Test Job ran and succeeded | |
if: always() && !(contains(needs.*.result, 'failure')) | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
# | |
# Build some metadata about the current repo, commit, pr etc to drive | |
# building and publishing the docker image | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
# list of Docker images to use as base name for tags | |
images: | | |
${{ github.repository_owner }}/mydrive | |
ghcr.io/${{ github.repository_owner }}/mydrive | |
# generate Docker tags based on the following events/attributes | |
tags: | | |
type=schedule,pattern={{date 'YYYYMMDD'}} | |
type=ref,event=branch | |
type=ref,event=pr | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}}.{{minor}} | |
type=semver,pattern={{major}} | |
type=sha | |
# | |
# Some build prep | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to DockerHub | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Login to GHCR | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# | |
# Build the image, tag it in required ways described by the 👆 metadata | |
# Use the docker layer cache from github actions cache | |
- name: Build and push | |
uses: docker/build-push-action@v3 | |
with: | |
context: . | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment