diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4106ceca7..b7c9ab663 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,10 +77,3 @@ jobs: mkdir -p spec/tmp bundle exec rails test bundle exec rspec --tag ~js - - docker: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Build image - run: docker build --tag image --file Dockerfile . diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 000000000..7af7f3213 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,84 @@ +name: Docker + +on: + push: + branches: + - main + - master + - develop + tags: + - "v*.*.*" + pull_request: + +jobs: + docker: + runs-on: ubuntu-latest + permissions: + packages: write + + steps: + - uses: actions/checkout@v4 + + # create metadata for image + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + # list of Docker images to use as base name for tags + images: | + pecan/bety + ghcr.io/${{ github.repository_owner }}/bety + # generate Docker tags based on the following events/attributes + tags: | + type=schedule + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + + # setup docker build + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v3 + + - name: Inspect Builder + run: | + echo "Name: ${{ steps.buildx.outputs.name }}" + echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}" + echo "Status: ${{ steps.buildx.outputs.status }}" + echo "Flags: ${{ steps.buildx.outputs.flags }}" + echo "Platforms: ${{ steps.buildx.outputs.platforms }}" + + # login to registries + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # build the docker images + - name: Build and push docker image + uses: docker/build-push-action@v5 + with: + context: . + #push: ${{ github.event_name != 'pull_request' }} + push: true + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: | + BETY_GIT_TAGS=${{ steps.meta.outputs.version }} + BETY_GIT_BRANCH=${{ github.ref_name }} + BETY_GIT_CHECKSUM=${{ github.sha }} + BETY_GIT_DATE=${{ github.event.head_commit.timestamp }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index e7fcbe436..000000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,73 +0,0 @@ -name: Release - -on: - push: - branches: - - master - - develop - tags: - - '*' - -jobs: - docker: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Build image - run: | - docker build \ - --build-arg BETY_GIT_TAGS="$(git log --pretty=format:%d -1)" \ - --build-arg BETY_GIT_BRANCH="$(git rev-parse --abbrev-ref HEAD)" \ - --build-arg BETY_GIT_CHECKSUM="$(git log --pretty=format:%H -1)" \ - --build-arg BETY_GIT_DATE="$(git log --pretty=format:%ad -1)" \ - --tag image --file Dockerfile . - - name: Login into registry - run: | - echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin - if [ -n "${{ secrets.DOCKERHUB_USERNAME }}" -a -n "${{ secrets.DOCKERHUB_PASSWORD }}" ]; then - echo "${{ secrets.DOCKERHUB_PASSWORD }}" | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin - fi - - name: Push image - run: | - # image all lowercase - IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/bety - 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//') - [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^betydb_//') - - # Use Docker `latest` tag convention - [ "$VERSION" == "master" ] && VERSION=latest - - # all tags we will apply - TMPVERSION="${VERSION}" - OLDVERSION="" - TAGS="" - while [ "$OLDVERSION" != "$TMPVERSION" ]; do - TAGS="${TAGS} ${TMPVERSION}" - OLDVERSION="${TMPVERSION}" - TMPVERSION=$(echo ${OLDVERSION} | sed 's/\.[0-9]*$//') - done - if [ "${TAGS}" == "" ]; then - TAGS="test" - fi - if [ "${TAGS}" == "master" ]; then - TAGS="latest" - fi - - echo IMAGE_ID=$IMAGE_ID - echo VERSION=$VERSION - echo TAGS=$TAGS - - # push all images - for T in $TAGS; do - docker tag image $IMAGE_ID:$T - docker push $IMAGE_ID:$T - if [ -n "${{ secrets.DOCKERHUB_USERNAME }}" -a -n "${{ secrets.DOCKERHUB_PASSWORD }}" ]; then - docker tag image pecan/bety:$T - docker push pecan/bety:$T - fi - done