Highlight uncommitted changes in version
If there are uncommitted changes in the app repository when building, then append `_uncommitted_<random>` to it to distinguish the image from one built from a clean checkout. Also change the version used when renaming a container on redeploy to distinguish and explain the version suffixes.
This commit is contained in:
@@ -32,7 +32,7 @@ class CliAppTest < CliTestCase
|
||||
|
||||
run_command("boot").tap do |output|
|
||||
assert_match /Renaming container .* to .* as already deployed on 1.1.1.1/, output # Rename
|
||||
assert_match /docker rename .* .*/, output
|
||||
assert_match /docker rename app-web-latest app-web-latest_replaced_[0-9a-f]{16}/, output
|
||||
assert_match "docker run --detach --restart unless-stopped", output
|
||||
assert_match "docker container ls --all --filter name=^app-web-123$ --quiet | xargs docker stop", output
|
||||
end
|
||||
|
||||
@@ -72,19 +72,36 @@ class ConfigurationTest < ActiveSupport::TestCase
|
||||
assert_equal [ "1.1.1.1", "1.1.1.2", "1.1.1.3" ], config.traefik_hosts
|
||||
end
|
||||
|
||||
test "version" do
|
||||
test "version no git repo" do
|
||||
ENV.delete("VERSION")
|
||||
|
||||
@config.expects(:system).with("git rev-parse").returns(nil)
|
||||
error = assert_raises(RuntimeError) { @config.version}
|
||||
assert_match /no git repository found/, error.message
|
||||
end
|
||||
|
||||
@config.expects(:current_commit_hash).returns("git-version")
|
||||
test "version from git committed" do
|
||||
ENV.delete("VERSION")
|
||||
|
||||
@config.expects(:`).with("git rev-parse HEAD").returns("git-version")
|
||||
@config.expects(:`).with("git status --porcelain").returns("")
|
||||
assert_equal "git-version", @config.version
|
||||
end
|
||||
|
||||
test "version from git uncommitted" do
|
||||
ENV.delete("VERSION")
|
||||
|
||||
@config.expects(:`).with("git rev-parse HEAD").returns("git-version")
|
||||
@config.expects(:`).with("git status --porcelain").returns("M file\n")
|
||||
assert_match /^git-version_uncommitted_[0-9a-f]{16}$/, @config.version
|
||||
end
|
||||
|
||||
test "version from env" do
|
||||
ENV["VERSION"] = "env-version"
|
||||
assert_equal "env-version", @config.version
|
||||
end
|
||||
|
||||
test "version from arg" do
|
||||
@config.version = "arg-version"
|
||||
assert_equal "arg-version", @config.version
|
||||
end
|
||||
|
||||
@@ -110,7 +110,7 @@ class DeployTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
def latest_app_version
|
||||
deployer_exec("cat version", capture: true)
|
||||
deployer_exec("git rev-parse HEAD", capture: true)
|
||||
end
|
||||
|
||||
def assert_app_version(version)
|
||||
|
||||
@@ -23,7 +23,6 @@ RUN mkdir -p /etc/docker/certs.d/registry:4443 && ln -s /shared/certs/domain.crt
|
||||
RUN git config --global user.email "deployer@example.com"
|
||||
RUN git config --global user.name "Deployer"
|
||||
RUN git init && git add . && git commit -am "Initial version"
|
||||
RUN git rev-parse HEAD > version
|
||||
|
||||
HEALTHCHECK --interval=1s CMD pgrep sleep
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
FROM nginx:1-alpine-slim
|
||||
|
||||
COPY default.conf /etc/nginx/conf.d/default.conf
|
||||
COPY version /usr/share/nginx/html/version
|
||||
|
||||
ARG COMMIT_SHA
|
||||
RUN echo $COMMIT_SHA > /usr/share/nginx/html/version
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ registry:
|
||||
password: root
|
||||
builder:
|
||||
multiarch: false
|
||||
args:
|
||||
COMMIT_SHA: <%= `git rev-parse HEAD` %>
|
||||
healthcheck:
|
||||
cmd: wget -qO- http://localhost > /dev/null
|
||||
traefik:
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
git commit -am 'Update rev' --amend
|
||||
git rev-parse HEAD > version
|
||||
|
||||
Reference in New Issue
Block a user