# HG changeset patch
# User Balasankar "Balu" C <balasankar@gitlab.com>
# Date 1613077581 0
#      Thu Feb 11 21:06:21 2021 +0000
# Node ID b35f79387af4c8b49e3915afcb60daefa7b74473
# Parent  68dd1b76fe20241e8b6b9f6f8fe0b384bcecfcdb
Make GitLab Docker image use Ubuntu 20.04 as base

Also switch QA to use Ubuntu 20.04 artifacts

Signed-off-by: Balasankar "Balu" C <balasankarc@autistici.org>

diff --git a/changelogs/unreleased/ubuntu-18-04-artifacts.yml b/changelogs/unreleased/ubuntu-18-04-artifacts.yml
new file mode 100644
--- /dev/null
+++ b/changelogs/unreleased/ubuntu-18-04-artifacts.yml
@@ -0,0 +1,5 @@
+---
+title: Make GitLab Docker image and AWS AMIs use Ubuntu 20.04 packages
+merge_request: 4876
+author:
+type: changed
diff --git a/docker/Dockerfile b/docker/Dockerfile
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -1,4 +1,4 @@
-FROM ubuntu:16.04
+FROM ubuntu:20.04
 MAINTAINER GitLab Inc. <support@gitlab.com>
 
 SHELL ["/bin/sh", "-c"],
diff --git a/gitlab-ci-config/dev-gitlab-org.yml b/gitlab-ci-config/dev-gitlab-org.yml
--- a/gitlab-ci-config/dev-gitlab-org.yml
+++ b/gitlab-ci-config/dev-gitlab-org.yml
@@ -425,15 +425,17 @@
   stage: gitlab_com:package
   extends: .branch_template
 
+Ubuntu-20.04-branch:
+  image: "${BUILDER_IMAGE_REGISTRY}/ubuntu_20.04:${BUILDER_IMAGE_REVISION}"
+  stage: gitlab_com:package
+  extends: .branch_template
+
 Debian-9-branch:
   image: "${BUILDER_IMAGE_REGISTRY}/debian_9:${BUILDER_IMAGE_REVISION}"
   <<: *branch_build
 Debian-10-branch:
   image: "${BUILDER_IMAGE_REGISTRY}/debian_10:${BUILDER_IMAGE_REVISION}"
   <<: *branch_build
-Ubuntu-20.04-branch:
-  image: "${BUILDER_IMAGE_REGISTRY}/ubuntu_20.04:${BUILDER_IMAGE_REVISION}"
-  <<: *branch_build
 Ubuntu-20.04-arm-branch:
   image: "${BUILDER_IMAGE_REGISTRY}/ubuntu_20.04_arm64:${BUILDER_IMAGE_REVISION}"
   <<: *branch_build
@@ -512,7 +514,7 @@
   - docker-builder
   cache: *branch-cache
   dependencies:
-    - Ubuntu-16.04-branch
+    - Ubuntu-20.04-branch
   retry: 1
 
 Raspberry-Pi-2-Buster-branch:
@@ -549,6 +551,11 @@
   stage: gitlab_com:package
   extends: .tag_template
 
+Ubuntu-20.04:
+  image: "${BUILDER_IMAGE_REGISTRY}/ubuntu_20.04:${BUILDER_IMAGE_REVISION}"
+  stage: gitlab_com:package
+  extends: .tag_template
+
 ## Build the docker image for QA
 ## This is necessary for the deployment
 ## pipeline so it must happen before
@@ -598,6 +605,14 @@
     - Ubuntu-18.04-branch
   <<: *dev-nightly-and-tag-except-auto-deploy
 
+Ubuntu-20.04-staging:
+  stage: gitlab_com:upload_deploy
+  extends: .staging_upload_template
+  dependencies:
+    - Ubuntu-20.04
+    - Ubuntu-20.04-branch
+  <<: *dev-nightly-and-tag-except-auto-deploy
+
 ### Package builds
 Debian-9:
   image: "${BUILDER_IMAGE_REGISTRY}/debian_9:${BUILDER_IMAGE_REVISION}"
@@ -605,9 +620,6 @@
 Debian-10:
   image: "${BUILDER_IMAGE_REGISTRY}/debian_10:${BUILDER_IMAGE_REVISION}"
   <<: *tag_build
-Ubuntu-20.04:
-  image: "${BUILDER_IMAGE_REGISTRY}/ubuntu_20.04:${BUILDER_IMAGE_REVISION}"
-  <<: *tag_build
 Ubuntu-20.04-arm:
   image: "${BUILDER_IMAGE_REGISTRY}/ubuntu_20.04_arm64:${BUILDER_IMAGE_REVISION}"
   <<: *tag_build
@@ -710,11 +722,6 @@
     - Debian-10
     - Debian-10-branch
   <<: *staging_upload
-Ubuntu-20.04-staging:
-  dependencies:
-    - Ubuntu-20.04
-    - Ubuntu-20.04-branch
-  <<: *staging_upload
 Ubuntu-20.04-arm-staging:
   dependencies:
     - Ubuntu-20.04-arm
@@ -856,7 +863,7 @@
   - docker-builder
   cache: *tag-cache
   dependencies:
-    - Ubuntu-16.04
+    - Ubuntu-20.04
   retry: 1
 
 upgrade:
diff --git a/gitlab-ci-config/gitlab-com.yml b/gitlab-ci-config/gitlab-com.yml
--- a/gitlab-ci-config/gitlab-com.yml
+++ b/gitlab-ci-config/gitlab-com.yml
@@ -57,7 +57,7 @@
 
 .trigger-package-cache:
   cache:
-    key: "Ubuntu-16.04-branch-${BUILDER_IMAGE_REVISION}-v1"
+    key: "Ubuntu-20.04-branch-${BUILDER_IMAGE_REVISION}-v1"
     paths:
       - cache
       - gems
@@ -171,7 +171,7 @@
 update-trigger-package-cache:
   extends: .trigger-package-cache
   stage: update-cache
-  image: "${BUILDER_IMAGE_REGISTRY}/ubuntu_16.04:${BUILDER_IMAGE_REVISION}"
+  image: "${BUILDER_IMAGE_REGISTRY}/ubuntu_20.04:${BUILDER_IMAGE_REVISION}"
   script:
     - *build-package
     - echo "Cache is up to date!"
@@ -374,13 +374,13 @@
 
 Trigger:package:
   extends: .trigger-package-cache
-  image: "${BUILDER_IMAGE_REGISTRY}/ubuntu_16.04:${BUILDER_IMAGE_REVISION}"
+  image: "${BUILDER_IMAGE_REGISTRY}/ubuntu_20.04:${BUILDER_IMAGE_REVISION}"
   stage: trigger-package
   script:
     - if [ -n "$TRIGGERED_USER" ] && [ -n "$TRIGGER_SOURCE" ]; then echo "Pipeline triggered by $TRIGGERED_USER at $TRIGGER_SOURCE"; fi
     - *build-package
     # Renaming so we can easily generate the artifact URL
-    - mv pkg/ubuntu-xenial/*.deb pkg/ubuntu-xenial/gitlab.deb
+    - mv pkg/ubuntu-focal/*.deb pkg/ubuntu-focal/gitlab.deb
     - bundle exec rspec --color --format RspecJunitFormatter --out junit_ci_rspec.xml --format documentation ci_build_specs
     - bundle exec rake build:component_shas
   <<: *com-trigger-only
diff --git a/lib/gitlab/build/ha_validate/nightly.rb b/lib/gitlab/build/ha_validate/nightly.rb
--- a/lib/gitlab/build/ha_validate/nightly.rb
+++ b/lib/gitlab/build/ha_validate/nightly.rb
@@ -17,7 +17,7 @@
       end
 
       def self.package_url
-        base_url = 'https://omnibus-builds.s3.amazonaws.com/ubuntu-xenial/gitlab-ee_'
+        base_url = 'https://omnibus-builds.s3.amazonaws.com/ubuntu-focal/gitlab-ee_'
         build_version = CGI.escape(Build::Info.semver_version)
         build_iteration = Gitlab::BuildIteration.new.build_iteration
         "#{base_url}#{build_version}-#{build_iteration}_amd64.deb"
diff --git a/lib/gitlab/build/ha_validate/tag.rb b/lib/gitlab/build/ha_validate/tag.rb
--- a/lib/gitlab/build/ha_validate/tag.rb
+++ b/lib/gitlab/build/ha_validate/tag.rb
@@ -14,7 +14,7 @@
       end
 
       def self.package_url
-        "https://downloads-packages.s3.amazonaws.com/ubuntu-xenial/gitlab-ee_#{version}_amd64.deb"
+        "https://downloads-packages.s3.amazonaws.com/ubuntu-focal/gitlab-ee_#{version}_amd64.deb"
       end
 
       def self.get_params(image: nil)
diff --git a/lib/gitlab/build/info.rb b/lib/gitlab/build/info.rb
--- a/lib/gitlab/build/info.rb
+++ b/lib/gitlab/build/info.rb
@@ -130,7 +130,7 @@
       # Fetch the package from an S3 bucket
       def package_download_url
         package_filename_url_safe = Info.release_version.gsub("+", "%2B")
-        "https://#{Info.release_bucket}.s3.amazonaws.com/ubuntu-xenial/#{Info.package}_#{package_filename_url_safe}_amd64.deb"
+        "https://#{Info.release_bucket}.s3.amazonaws.com/ubuntu-focal/#{Info.package}_#{package_filename_url_safe}_amd64.deb"
       end
 
       def get_api(path, token: nil)
@@ -158,7 +158,7 @@
         return unless project_id && !project_id.empty? && pipeline_id && !pipeline_id.empty?
 
         id = fetch_artifact_url(project_id, pipeline_id)
-        "https://gitlab.com/api/v4/projects/#{Gitlab::Util.get_env('CI_PROJECT_ID')}/jobs/#{id}/artifacts/pkg/ubuntu-xenial/gitlab.deb"
+        "https://gitlab.com/api/v4/projects/#{Gitlab::Util.get_env('CI_PROJECT_ID')}/jobs/#{id}/artifacts/pkg/ubuntu-focal/gitlab.deb"
       end
 
       def tag_match_pattern
diff --git a/lib/gitlab/build/qa.rb b/lib/gitlab/build/qa.rb
--- a/lib/gitlab/build/qa.rb
+++ b/lib/gitlab/build/qa.rb
@@ -27,7 +27,7 @@
     def self.get_gitlab_rails_sha
       # Finding out which commit was the package built from
       begin
-        version_manifest = JSON.parse(File.read("pkg/ubuntu-xenial/#{Build::Info.package}_#{Build::Info.release_version}.version-manifest.json"))
+        version_manifest = JSON.parse(File.read("pkg/ubuntu-focal/#{Build::Info.package}_#{Build::Info.release_version}.version-manifest.json"))
         version = version_manifest['software']['gitlab-rails']['locked_version']
       rescue Errno::ENOENT, JSON::ParserError
         puts "Failed to get commit from version-manifest file"
diff --git a/spec/gitlab/build/ha_validate/nightly_spec.rb b/spec/gitlab/build/ha_validate/nightly_spec.rb
--- a/spec/gitlab/build/ha_validate/nightly_spec.rb
+++ b/spec/gitlab/build/ha_validate/nightly_spec.rb
@@ -2,7 +2,7 @@
 require 'gitlab/build/ha_validate/nightly'
 
 RSpec.describe Build::HA::ValidateNightly do
-  let(:expected_url) { 'https://omnibus-builds.s3.amazonaws.com/ubuntu-xenial/gitlab-ee_99.9.9%2Brfbranch-55_amd64.deb' }
+  let(:expected_url) { 'https://omnibus-builds.s3.amazonaws.com/ubuntu-focal/gitlab-ee_99.9.9%2Brfbranch-55_amd64.deb' }
 
   before do
     allow(Build::Info).to receive(:semver_version).and_return('99.9.9+rfbranch')
diff --git a/spec/gitlab/build/image_spec.rb b/spec/gitlab/build/image_spec.rb
--- a/spec/gitlab/build/image_spec.rb
+++ b/spec/gitlab/build/image_spec.rb
@@ -94,7 +94,7 @@
         [
           "PACKAGECLOUD_REPO=download-package",
           "RELEASE_VERSION=12.121.12-ce.1",
-          "DOWNLOAD_URL=https://gitlab.com/api/v4/projects/1/jobs/1/artifacts/pkg/ubuntu-xenial/gitlab.deb",
+          "DOWNLOAD_URL=https://gitlab.com/api/v4/projects/1/jobs/1/artifacts/pkg/ubuntu-focal/gitlab.deb",
           "TRIGGER_PRIVATE_TOKEN=NOT-PRIVATE-TOKEN\n"
         ]
       end
@@ -133,7 +133,7 @@
       end
 
       describe 'with regular build' do
-        let(:s3_download_link) { 'https://downloads-packages.s3.amazonaws.com/ubuntu-xenial/gitlab-ee_12.121.12-ce.1_amd64.deb' }
+        let(:s3_download_link) { 'https://downloads-packages.s3.amazonaws.com/ubuntu-focal/gitlab-ee_12.121.12-ce.1_amd64.deb' }
 
         let(:release_file) do
           [
diff --git a/spec/gitlab/package_repository_spec.rb b/spec/gitlab/package_repository_spec.rb
--- a/spec/gitlab/package_repository_spec.rb
+++ b/spec/gitlab/package_repository_spec.rb
@@ -175,7 +175,7 @@
       context 'with artifacts available' do
         before do
           stub_env_var('PACKAGECLOUD_USER', "gitlab")
-          allow(Dir).to receive(:glob).with("pkg/**/*.{deb,rpm}").and_return(['pkg/ubuntu-xenial/gitlab.deb'])
+          allow(Dir).to receive(:glob).with("pkg/**/*.{deb,rpm}").and_return(['pkg/ubuntu-focal/gitlab.deb'])
         end
 
         context 'for stable release' do
@@ -192,7 +192,7 @@
 
             it 'in dry run mode prints the upload commands' do
               expect { repo.upload(nil, true) }.to output(%r{Uploading...\n}).to_stdout
-              expect { repo.upload(nil, true) }.to output(%r{bin/package_cloud push gitlab/gitlab-ee/ubuntu/xenial pkg/ubuntu-xenial/gitlab.deb --url=https://packages.gitlab.com\n}).to_stdout
+              expect { repo.upload(nil, true) }.to output(%r{bin/package_cloud push gitlab/gitlab-ee/ubuntu/focal pkg/ubuntu-focal/gitlab.deb --url=https://packages.gitlab.com\n}).to_stdout
             end
           end
 
@@ -203,7 +203,7 @@
 
             it 'in dry run mode prints the upload commands' do
               expect { repo.upload(nil, true) }.to output(%r{Uploading...\n}).to_stdout
-              expect { repo.upload(nil, true) }.to output(%r{bin/package_cloud push gitlab/gitlab-ce/ubuntu/xenial pkg/ubuntu-xenial/gitlab.deb --url=https://packages.gitlab.com\n}).to_stdout
+              expect { repo.upload(nil, true) }.to output(%r{bin/package_cloud push gitlab/gitlab-ce/ubuntu/focal pkg/ubuntu-focal/gitlab.deb --url=https://packages.gitlab.com\n}).to_stdout
             end
           end
         end
@@ -216,7 +216,7 @@
 
           it 'in dry run mode prints the upload commands' do
             expect { repo.upload(Gitlab::Util.get_env('STAGING_REPO'), true) }.to output(%r{Uploading...\n}).to_stdout
-            expect { repo.upload(Gitlab::Util.get_env('STAGING_REPO'), true) }.to output(%r{bin/package_cloud push gitlab/nightly-builds/ubuntu/xenial pkg/ubuntu-xenial/gitlab.deb --url=https://packages.gitlab.com\n}).to_stdout
+            expect { repo.upload(Gitlab::Util.get_env('STAGING_REPO'), true) }.to output(%r{bin/package_cloud push gitlab/nightly-builds/ubuntu/focal pkg/ubuntu-focal/gitlab.deb --url=https://packages.gitlab.com\n}).to_stdout
           end
         end
 
@@ -228,7 +228,7 @@
 
           it 'in dry run mode prints the upload commands' do
             expect { repo.upload(nil, true) }.to output(%r{Uploading...\n}).to_stdout
-            expect { repo.upload(nil, true) }.to output(%r{bin/package_cloud push gitlab/raspi/ubuntu/xenial pkg/ubuntu-xenial/gitlab.deb --url=https://packages.gitlab.com\n}).to_stdout
+            expect { repo.upload(nil, true) }.to output(%r{bin/package_cloud push gitlab/raspi/ubuntu/focal pkg/ubuntu-focal/gitlab.deb --url=https://packages.gitlab.com\n}).to_stdout
           end
         end
       end
@@ -238,7 +238,7 @@
       before do
         stub_env_var('PACKAGECLOUD_USER', "gitlab")
         set_all_env_variables
-        allow(Dir).to receive(:glob).with("pkg/**/*.{deb,rpm}").and_return(['pkg/ubuntu-xenial/gitlab.deb', 'pkg/ubuntu-xenial/testing/gitlab.deb'])
+        allow(Dir).to receive(:glob).with("pkg/**/*.{deb,rpm}").and_return(['pkg/ubuntu-focal/gitlab.deb', 'pkg/ubuntu-focal/testing/gitlab.deb'])
       end
 
       it 'raises an exception' do
diff --git a/support/packer/ce.json b/support/packer/ce.json
--- a/support/packer/ce.json
+++ b/support/packer/ce.json
@@ -13,7 +13,7 @@
     "source_ami_filter": {
       "filters": {
         "virtualization-type": "hvm",
-        "name": "ubuntu/images/*ubuntu-xenial-16.04-amd64-server-*",
+        "name": "ubuntu/images/*ubuntu-focal-20.04-amd64-server-*",
         "root-device-type": "ebs"
       },
       "owners": ["099720109477"],
diff --git a/support/packer/ee-premium.json b/support/packer/ee-premium.json
--- a/support/packer/ee-premium.json
+++ b/support/packer/ee-premium.json
@@ -14,7 +14,7 @@
     "source_ami_filter": {
       "filters": {
         "virtualization-type": "hvm",
-        "name": "ubuntu/images/*ubuntu-xenial-16.04-amd64-server-*",
+        "name": "ubuntu/images/*ubuntu-focal-20.04-amd64-server-*",
         "root-device-type": "ebs"
       },
       "owners": ["099720109477"],
diff --git a/support/packer/ee-ultimate.json b/support/packer/ee-ultimate.json
--- a/support/packer/ee-ultimate.json
+++ b/support/packer/ee-ultimate.json
@@ -14,7 +14,7 @@
     "source_ami_filter": {
       "filters": {
         "virtualization-type": "hvm",
-        "name": "ubuntu/images/*ubuntu-xenial-16.04-amd64-server-*",
+        "name": "ubuntu/images/*ubuntu-focal-20.04-amd64-server-*",
         "root-device-type": "ebs"
       },
       "owners": ["099720109477"],
diff --git a/support/packer/ee.json b/support/packer/ee.json
--- a/support/packer/ee.json
+++ b/support/packer/ee.json
@@ -13,7 +13,7 @@
     "source_ami_filter": {
       "filters": {
         "virtualization-type": "hvm",
-        "name": "ubuntu/images/*ubuntu-xenial-16.04-amd64-server-*",
+        "name": "ubuntu/images/*ubuntu-focal-20.04-amd64-server-*",
         "root-device-type": "ebs"
       },
       "owners": ["099720109477"],