Skip to content

Commit

Permalink
ci: use new docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
kruserr committed Feb 23, 2024
1 parent 876825a commit bb90a41
Show file tree
Hide file tree
Showing 2 changed files with 227 additions and 126 deletions.
226 changes: 142 additions & 84 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,88 +81,146 @@ jobs:
cargo publish -p rapiddb --token ${{ secrets.CARGO_TOKEN }}
cargo publish -p rapiddb-web --token ${{ secrets.CARGO_TOKEN }}
publish-docker:
name: Publish on GitHub Packages and Docker Hub
needs:
- rustfmt
- clippy
- test
runs-on: ubuntu-22.04
if: github.event_name == 'push'
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Build image
run: |
docker build \
-f tooling/Dockerfile \
--cache-from $IMAGE_CACHE \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--tag $IMAGE_NAME .
- name: Login to GitHub Packages
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
- name: Push image to GitHub Packages
run: |
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Strip patch version from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION_MINOR=${VERSION%.*}
# Strip minor version from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION_MAJOR=${VERSION_MINOR%.*}
# publish-docker:
# name: Publish on GitHub Packages and Docker Hub
# needs:
# - rustfmt
# - clippy
# - test
# runs-on: ubuntu-22.04
# if: github.event_name == 'push'
# permissions:
# contents: read
# packages: write
# steps:
# - name: Checkout
# uses: actions/checkout@v3
# - name: Build image
# run: |
# docker build \
# -f tooling/Dockerfile \
# --cache-from $IMAGE_CACHE \
# --build-arg BUILDKIT_INLINE_CACHE=1 \
# --tag $IMAGE_NAME .
# - name: Login to GitHub Packages
# run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
# - name: Push image to GitHub Packages
# run: |
# IMAGE_ID=ghcr.io/${{ github.repository }}/$IMAGE_NAME

# # Change all uppercase to lowercase
# IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')

# # Strip git ref prefix from version
# VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')

# # Strip "v" prefix from tag name
# [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')

# # Strip patch version from tag name
# [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION_MINOR=${VERSION%.*}

# # Strip minor version from tag name
# [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION_MAJOR=${VERSION_MINOR%.*}

# docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
# docker push $IMAGE_ID:$VERSION

# docker tag $IMAGE_NAME $IMAGE_ID:$VERSION_MINOR
# docker push $IMAGE_ID:$VERSION_MINOR

# docker tag $IMAGE_NAME $IMAGE_ID:$VERSION_MAJOR
# docker push $IMAGE_ID:$VERSION_MAJOR

# docker tag $IMAGE_NAME $IMAGE_ID:latest
# docker push $IMAGE_ID:latest
# - name: Login to Docker Hub
# run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login docker.io -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
# - name: Push image to Docker Hub
# run: |
# IMAGE_ID=docker.io/${{ github.repository }}

# # Change all uppercase to lowercase
# IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')

# # Strip git ref prefix from version
# VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')

# # Strip "v" prefix from tag name
# [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')

# # Strip patch version from tag name
# [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION_MINOR=${VERSION%.*}

# # Strip minor version from tag name
# [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION_MAJOR=${VERSION_MINOR%.*}

# docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
# docker push $IMAGE_ID:$VERSION

# docker tag $IMAGE_NAME $IMAGE_ID:$VERSION_MINOR
# docker push $IMAGE_ID:$VERSION_MINOR

# docker tag $IMAGE_NAME $IMAGE_ID:$VERSION_MAJOR
# docker push $IMAGE_ID:$VERSION_MAJOR

# docker tag $IMAGE_NAME $IMAGE_ID:latest
# docker push $IMAGE_ID:latest

build-and-push:
runs-on: ubuntu-latest

docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION_MINOR
docker push $IMAGE_ID:$VERSION_MINOR
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION_MAJOR
docker push $IMAGE_ID:$VERSION_MAJOR
docker tag $IMAGE_NAME $IMAGE_ID:latest
docker push $IMAGE_ID:latest
- name: Login to Docker Hub
run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login docker.io -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
- name: Push image to Docker Hub
run: |
IMAGE_ID=docker.io/${{ github.repository }}
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Strip patch version from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION_MINOR=${VERSION%.*}
# Strip minor version from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION_MAJOR=${VERSION_MINOR%.*}
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION_MINOR
docker push $IMAGE_ID:$VERSION_MINOR
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION_MAJOR
docker push $IMAGE_ID:$VERSION_MAJOR
docker tag $IMAGE_NAME $IMAGE_ID:latest
docker push $IMAGE_ID:latest
steps:
- name: Checkout code
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-
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Login to Docker Hub
uses: docker/login-action@v1
with:
registry: docker.io
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Extract version
id: extract_version
run: |
VERSION=${GITHUB_REF#refs/tags/v}
echo "::set-output name=version::${VERSION}"
echo "::set-output name=major::${VERSION%%.*}"
echo "::set-output name=minor::${VERSION%.*}"
echo "::set-output name=patch::${VERSION##*.}"
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: |
ghcr.io/${{ github.repository }}:latest
ghcr.io/${{ github.repository }}:${{ steps.extract_version.outputs.version }}
ghcr.io/${{ github.repository }}:${{ steps.extract_version.outputs.major }}
ghcr.io/${{ github.repository }}:${{ steps.extract_version.outputs.minor }}
docker.io/${{ github.repository }}:latest
docker.io/${{ github.repository }}:${{ steps.extract_version.outputs.version }}
docker.io/${{ github.repository }}:${{ steps.extract_version.outputs.major }}
docker.io/${{ github.repository }}:${{ steps.extract_version.outputs.minor }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
127 changes: 85 additions & 42 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,46 +44,89 @@ jobs:
- name: Test
run: cargo test

publish-docker:
name: Publish on GitHub Packages and Docker Hub
runs-on: ubuntu-22.04
if: github.event_name == 'push'
permissions:
contents: read
packages: write
# publish-docker:
# name: Publish on GitHub Packages and Docker Hub
# runs-on: ubuntu-22.04
# if: github.event_name == 'push'
# permissions:
# contents: read
# packages: write
# steps:
# - name: Checkout
# uses: actions/checkout@v3
# - name: Build image
# run: |
# docker build \
# -f tooling/Dockerfile \
# --cache-from $IMAGE_CACHE \
# --build-arg BUILDKIT_INLINE_CACHE=1 \
# --tag $IMAGE_NAME .
# - name: Login to GitHub Packages
# run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
# - name: Push image to GitHub Packages
# run: |
# IMAGE_ID=ghcr.io/${{ github.repository }}/$IMAGE_NAME

# # Change all uppercase to lowercase
# IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')

# VERSION=cache

# docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
# docker push $IMAGE_ID:$VERSION
# - name: Login to Docker Hub
# run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login docker.io -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
# - name: Push image to Docker Hub
# run: |
# IMAGE_ID=docker.io/${{ github.repository }}

# # Change all uppercase to lowercase
# IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')

# VERSION=cache

# docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
# docker push $IMAGE_ID:$VERSION

build-and-push:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Build image
run: |
docker build \
-f tooling/Dockerfile \
--cache-from $IMAGE_CACHE \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--tag $IMAGE_NAME .
- name: Login to GitHub Packages
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
- name: Push image to GitHub Packages
run: |
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
VERSION=cache
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
- name: Login to Docker Hub
run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login docker.io -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
- name: Push image to Docker Hub
run: |
IMAGE_ID=docker.io/${{ github.repository }}
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
VERSION=cache
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
- name: Checkout code
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-
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Login to Docker Hub
uses: docker/login-action@v1
with:
registry: docker.io
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: |
ghcr.io/${{ github.repository }}:dev
docker.io/${{ github.repository }}:dev
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache

0 comments on commit bb90a41

Please sign in to comment.