Moving repository from Bitbucket to Github
I have been using Bitbucket for 10+ years now. The main reason why I chose Bitbucket over Github back then is because Bitbucket was offering unlimited private repositories for free, and Github was not. Since 2019 Github is also offering unlimited private repositories for free, but I did not make the switch at that time, because by the time I took note of this new offering Bitbucket had already introduced Bitbucket Pipelines, which I had grown accustomed to. However times have changed, and Github has introduced Github Actions, which I have been using successfuly for some time now.
This is why I decided it was time to move the repository for this blog from Bitbucket to Github. For this I took the following steps:
- add new github remote (
git remote add github git@github.com:knapenio/blog.git
) - push to github (
git push github master
) - create Github Actions workflow (
.github/workflows/deploy.yml
) - push to github
- watch Action fail
- edit workflow
- push to github
- repeat (5), (6) and (7) about 10 times until the deployment succeeds
Final Github Actions configuration
name: Deploy
on:
push:
branches:
- master
jobs:
build-deploy:
runs-on: ubuntu-latest
environment: production
steps:
-
uses: actions/checkout@v3
-
name: Build
uses: ruby/setup-ruby@v1
with:
ruby-version: '2.6'
bundler-cache: true
-
run: |
bundle config set --local path 'vendor/bundle'
bundle install
JEKYLL_ENV=production bundle exec jekyll build --destination public
-
name: Deploy on server
uses: up9cloud/action-rsync@v1.3
env:
HOST: $
KEY: $
USER: $
SOURCE: ./public/
TARGET: websites/io.knapen.blog/htdocs
ARGS: -crltDzv --delete-delay --exclude=/.git/ --exclude=/.github/
Original Bitbucket Pipelines configuration
image: ruby:latest
pipelines:
branches:
master:
- step:
name: Generate the blog with Jekyll
caches:
- bundler
script:
- bundle install --path vendor/bundle
- JEKYLL_ENV=production bundle exec jekyll build --destination public
- mkdir dist
- tar -czvf dist/package-${BITBUCKET_BUILD_NUMBER}.tar.gz -C public .
artifacts:
- dist/**
- step:
name: Deploy to Production
image: alpine
deployment: production
trigger: manual
script:
- mkdir upload && tar -xf dist/package-${BITBUCKET_BUILD_NUMBER}.tar.gz -C upload
- apk update && apk add openssh rsync
- rsync -crltDzv upload/ $DEPLOY_URL:www/io.knapen.blog/htdocs --delete-delay
definitions:
caches:
bundler: vendor/bundle
Final notes
Attentive readers will have noticed my Github Actions configuration does not match the Bitbucket Pipelines configuration 100%. More specifically I merged the separate build and deploy steps into 1 single step, because I could not get the artifacts going on Github. Maybe in the future I might get back to this and give it another go, but for now this will have to do.