diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 436fac1a14f273f6656b797ab72b04643b8c6f5e..22581ec6340092c4f5a4fd9a3ca9edae4b0d1c42 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,34 +1,51 @@ -image: ruby:3.2.2-bookworm +image: alpine:latest -variables: - JEKYLL_ENV: production - LC_ALL: C.UTF-8 - -build-page: - stage: build - - variables: - JEKYLL_ENV: production +stages: + - deploy +deploy-to-2024-website: + stage: deploy + rules: + - if: $CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE == "push" before_script: - - gem install bundler - - bundle install - - wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 --no-verbose -O /usr/local/bin/yq - - chmod +x /usr/local/bin/yq - + # Install rsync and SSH client, set up SSH agent, and configure SSH + - apk update && apk add --no-cache rsync openssh + - eval $(ssh-agent -s) + - echo "$MUDE_DEPLOYER_SSH_KEY" | tr -d '\r' | ssh-add - + - mkdir -p ~/.ssh + - chmod 700 ~/.ssh + - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config script: - - chmod +x ./build-page.sh + # Debug information: show current directory and list files + - 'echo "Current directory: $PWD"' + - ls -la + # Create and set permissions on the target directory on the remote server + - ssh $MUDE_SERVER_USER@$MUDE_SERVER_ADDRESS "sudo mkdir -p /var/web_server/htdocs/2024-website" + - ssh $MUDE_SERVER_USER@$MUDE_SERVER_ADDRESS "sudo chown -R $MUDE_SERVER_USER:$MUDE_SERVER_USER /var/web_server/htdocs/2024-website" + # Sync files to the remote server, excluding unnecessary directories + - rsync -avz --delete-after --exclude=".git/" --exclude=".cache/" ./ $MUDE_SERVER_USER@$MUDE_SERVER_ADDRESS:/var/web_server/htdocs/2024-website/ + # Install Jekyll and build the site on the remote server - | - if [ "$CI_COMMIT_BRANCH" == "publish" ]; then - echo "Running on publish branch" - ./build-page.sh "/" true - else - echo "Running on main branch" - ./build-page.sh /draft false - fi - artifacts: - paths: - - public - rules: - - if: $CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE == "push" - - if: $CI_COMMIT_BRANCH == "publish" && $CI_PIPELINE_SOURCE == "push" + ssh $MUDE_SERVER_USER@$MUDE_SERVER_ADDRESS " + # Update package lists + sudo apt-get update + # Install Ruby and other dependencies + sudo apt-get install -y ruby-full build-essential zlib1g-dev + # Set up Ruby Gems to install to the user's home directory + echo '# Install Ruby Gems to ~/gems' >> ~/.bashrc + echo 'export GEM_HOME=\"\$HOME/gems\"' >> ~/.bashrc + echo 'export PATH=\"\$HOME/gems/bin:\$PATH\"' >> ~/.bashrc + source ~/.bashrc + # Install Jekyll and Bundler + gem install jekyll bundler + # Navigate to the project directory and build the site + cd /var/web_server/htdocs/2024-website + bundle install + JEKYLL_ENV=production bundle exec jekyll build --destination _site + # Ensure correct permissions for the _site directory + sudo chown -R $MUDE_SERVER_USER:$MUDE_SERVER_USER _site + sudo chmod -R 755 _site + " + environment: + name: production + url: https://mude.citg.tudelft.nl/2024-website \ No newline at end of file