Skip to content

Commit

Permalink
Implement Github Actions CI workflow
Browse files Browse the repository at this point in the history
Naive Jenkinsfile to GH Actions workflow

Add naive ci-cd pipeline

Update ci pipeline

diff --git a/.github/workflows/ci-cd-pipeline.yml b/.github/workflows/ci-cd-pipeline.yml
index ba2ec6b..a86e7d1 100644
--- a/.github/workflows/ci-cd-pipeline.yml
+++ b/.github/workflows/ci-cd-pipeline.yml
@@ -1,81 +1,32 @@
-name: CI/CD Pipeline
+name: ci

 on:
-  push
+  push:
+    branches:
+      - '*'
+      # - 'main'

 jobs:
-  build:
+  docker:
     runs-on: ubuntu-latest
-
-    env:
-      repository: guppy_server
-
     steps:
-    - name: Checkout code
-      uses: actions/checkout@v2
-
-    - name: Set version
-      id: set-version
-      run: echo "::set-output name=version::$(date -d @$(git log -1 --format=%at) +%Y%m%d%Z%H%M)-${{ github.ref_name }}"
-
-    - name: Set datetime
-      id: set-datetime
-      run: echo "::set-output name=datetime::$(date -d @$(git log -1 --format=%at) +%Y%m%d%Z%H%M)"
-
-    - name: Build conda-env docker image
-      run: docker build --target conda-env -t ghcr.io/${{ github.repository_owner }}/${{ env.repository }}_conda-env:latest-${{ github.ref_name }} server
-
-    - name: Build docker image
-      run: |
-        docker build -t ghcr.io/${{ github.repository_owner }}/${{ env.repository }}:latest-${{ github.ref_name }} server
-        echo "::set-output name=dockerImage::ghcr.io/${{ github.repository_owner }}/${{ env.repository }}:latest-${{ github.ref_name }}"
-
-    - name: Run unittests
-      run: docker run --rm ${{ steps.build.outputs.dockerImage }} /opt/guppy/server/conda-env/bin/python -m unittest discover -s server -v
-
-    # - name: Login to GitHub Container Registry
-    #   run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
-
-    # - name: Push docker image to registry
-    #   run: |
-    #     docker push ghcr.io/${{ github.repository_owner }}/${{ env.repository }}:${{ env.version }}
-    #     if [[ ${{ github.ref_name }} =~ ^(main|master)$ ]]; then
-    #       docker push ghcr.io/${{ github.repository_owner }}/${{ env.repository }}:latest
-    #       docker push ghcr.io/${{ github.repository_owner }}/${{ env.repository }}:${{ env.datetime }}
-    #     fi
-    #     if [[ ${{ github.ref }} =~ refs/tags/ ]]; then
-    #       tag="${{ github.ref#refs/tags/ }}"
-    #       docker push ghcr.io/${{ github.repository_owner }}/${{ env.repository }}:${tag}
-    #     else
-    #       docker push ghcr.io/${{ github.repository_owner }}/${{ env.repository }}:latest-${{ github.ref_name }}
-
-    # - name: Cleanup
-    #   run: |
-    #     docker image rm ghcr.io/${{ github.repository_owner }}/${{ env.repository }}:${{ env.version }}
-    #     if [[ ${{ github.ref_name }} =~ ^(main|master)$ ]]; then
-    #       docker image rm ghcr.io/${{ github.repository_owner }}/${{ env.repository }}:latest
-    #       docker image rm ghcr.io/${{ github.repository_owner }}/${{ env.repository }}:${{ env.datetime }}
-    #     fi
-    #     if [[ ${{ github.ref }} =~ refs/tags/ ]]; then
-    #       tag="${{ github.ref#refs/tags/ }}"
-    #       docker image rm ghcr.io/${{ github.repository_owner }}/${{ env.repository }}:${tag}
-    #     else
-    #       docker image rm ghcr.io/${{ github.repository_owner }}/${{ env.repository }}:latest-${{ github.ref_name }}
-
-    # - name: Update services
-    #   if: github.ref_name == 'develop' || github.ref_name == 'main' || github.ref_name == 'master'
-    #   run: |
-    #     deploy_branch=""
-    #     if [[ ${{ github.ref_name }} == 'develop' ]]; then
-    #       deploy_branch=${{ env.deploy_test_branch }}
-    #     elif [[ ${{ github.ref_name }} =~ ^(main|master)$ ]]; then
-    #       deploy_branch=${{ env.deploy_prod_branch }}
-    #     fi
-    #     if [ -z "$deploy_branch" ]; then
-    #       echo "Skipping service update: $deploy_project/$deploy_branch does not exist yet!"
-    #     else
-    #       echo "Updating services for $deploy_project/$deploy_branch"
-    #       # Add the actual service update logic here
-
-    # - name: Clean up
-    #   run: rm -rf ${{ github.workspace }}
+      -
+        name: Set up QEMU
+        uses: docker/setup-qemu-action@v3
+      -
+        name: Set up Docker Buildx
+        uses: docker/setup-buildx-action@v3
+      -
+        name: Login to Docker Hub
+        uses: docker/login-action@v3
+        with:
+          username: ${{ secrets.DOCKERHUB_USERNAME }}
+          password: ${{ secrets.DOCKERHUB_TOKEN }}
+      -
+        name: Build and push
+        uses: docker/build-push-action@v6
+        with:
+          push: true
+          tags: user/app:latest
+          context: ./server
+          file: ./server/Dockerfile
\ No newline at end of file

Checkout code as first GH-CI workflow step

Add corect dockerhub tag

Push to dockerhub organisation vitobelgium

Add docker action cache

Add latest/latest-dev tag

Add support for other branches (integration mode)
  • Loading branch information
hoetmaaiers committed Jun 26, 2024
1 parent fb45a29 commit 7f25345
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/ci-cd-pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: ci

on:
push:
branches:
- 'main'
- 'develop'
- 'feature/github-actions'

jobs:
dockerhub-build-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: List directory structure
run: ls -lah
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Generate timestamp
id: timestamp
run: echo "TIMESTAMP=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV
- name: Determine tag
id: tag
run: |
BRANCH_NAME="${GITHUB_REF#refs/heads/}"
NORMALIZED_BRANCH_NAME="${BRANCH_NAME/\//-}"
if [[ $BRANCH_NAME == 'main' ]]; then
echo "::set-output name=tag::latest"
elif [[ $BRANCH_NAME == 'develop' ]]; then
echo "::set-output name=tag::latest-dev"
else
echo "::set-output name=tag::${NORMALIZED_BRANCH_NAME}"
fi
- name: Build and push
uses: docker/build-push-action@v6
with:
push: true
tags: |
vitobelgium/guppy:${{ steps.tag.outputs.tag }}
vitobelgium/guppy:${{ env.TIMESTAMP }}
context: ./server
file: ./server/Dockerfile
cache-from: type=gha
cache-to: type=gha,mode=max

0 comments on commit 7f25345

Please sign in to comment.