Skip to content

Commit

Permalink
Merge pull request #34 from FRINXio/docker_build
Browse files Browse the repository at this point in the history
Build generic image with yang schemas for kubernetes deployment
  • Loading branch information
Jozefiel authored May 6, 2024
2 parents 37c0d29 + 91c804d commit be03dde
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.dockerignore
.github
.git
56 changes: 56 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Docker

on:
push:
# Publish `main` and `stable` as Docker `latest` image.
branches:
- 'main'
- '[0-9]+.X-stable'

# Publish `v1.2.3` tags as releases.
tags:
- 'v*'
- 'v[0-9]+.[0-9]+.[0-9]-stable'

env:
IMAGE_NAME: frinx/yang-schemas

jobs:
push:
runs-on: ubuntu-latest
if: github.event_name == 'push'

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set tag for latest image
if: github.ref_type == 'branch' && startsWith(github.ref, 'refs/heads/main')
run: |
echo "IMAGE_TAG=$(echo 'latest')" >> "$GITHUB_ENV"
- name: Set tag for stable-latest image
if: github.ref_type == 'branch' && endsWith(github.ref, '-stable')
run: |
echo "IMAGE_TAG=$(echo 'stable-latest')" >> "$GITHUB_ENV"
- name: Set tag for stable-release image
if: github.ref_type == 'tag' && endsWith(github.ref, '-stable')
run: |
echo "IMAGE_TAG=$(echo $GITHUB_REF | cut -d / -f 3 | sed -e 's/^v//' | sed -e 's/-stable//')" >> "$GITHUB_ENV"
- name: Set tag for release image
if: ${{ github.ref_type == 'tag' && !endsWith(github.ref, '-stable') }}
run: |
echo "IMAGE_TAG=$(echo $GITHUB_REF | cut -d / -f 3 | sed -e 's/^v//')" >> "$GITHUB_ENV"
- name: Build image
run: docker build . --file Dockerfile --build-arg git_commit=$(git rev-parse HEAD) --tag $IMAGE_NAME:${IMAGE_TAG}

- name: Log into docker hub
run: echo "${{ secrets.DOCKER_HUB_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin

- name: Push image
run: |
docker push $IMAGE_NAME:${IMAGE_TAG}
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM alpine

ARG git_commit=unspecified
LABEL git_commit="${git_commit}"
LABEL org.opencontainers.image.source="https://github.com/FRINXio/yang-schemas"

ARG USER=frinx
ENV HOME /home/$USER
RUN adduser -D $USER --home ${HOME}
USER $USER
WORKDIR $HOME

COPY ./ ${HOME}/yang-schemas

0 comments on commit be03dde

Please sign in to comment.