我之前是通过本地计算机部署应用程序的:
// preferences[i][j] is jth preference for voter i
int preferences[MAX_VOTERS][MAX_CANDIDATES];
// Candidates have name, vote count, eliminated status
typedef struct
{
string name;
int votes;
bool eliminated;
}
candidate;
// Array of candidates
candidate candidates[MAX_CANDIDATES];
// Numbers of voters and candidates
int voter_count;
int candidate_count;
// Function prototypes
bool vote(int voter, int rank, string name);
int main(int argc, string argv[])
{
// Populate array of candidates
candidate_count = argc - 1;
for (int i = 0; i < candidate_count; i++)
{
candidates[i].name = argv[i + 1];
candidates[i].votes = 0;
candidates[i].eliminated = false;
}
voter_count = get_int("Number of voters: ");
// Keep querying for votes
for (int i = 0; i < voter_count; i++)
{
// Query for each rank
for (int j = 0; j < candidate_count; j++)
{
string name = get_string("Rank %i: ", j + 1);
// Record vote, unless it's invalid
if (!vote(i, j, name))
{
printf("Invalid vote.\n");
return 4;
}
}
printf("\n");
}
// Record preference if vote is valid
bool vote(int voter, int rank, string name)
{
// TODO
for (int i = 0; i < candidate_count; i++)
{
**if (strcmp(candidates[i].name, name) == 0)**
{
preferences[voter][rank] = i;
return true;
}
}
return false;
}
这成功,所有Dockerfiles都正确。 现在我想在GitLab CI上做同样的事情。这是我用于构建的gitlab-ci.yml文件:
> docker context create remote --docker "host=ssh://user@myhost"
> docker --context remote ps
> docker-compose --context remote build
> docker-compose --context remote up -d
一切都在image: docker:19.03.12
services:
- docker:dind
stages:
- build
install_dependencies:
stage: build
before_script:
- 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "StrictHostKeyChecking no " > ~/.ssh/config
script:
- echo "Building deploy package"
- echo "$NPMRC" > ~/.npmrc
- apk add --no-cache docker-compose
- docker context create remote --docker "host=ssh://user@myhost"
- docker --context remote ps
- docker context use remote
- docker-compose --context remote build
- echo "Build successful"
之前,当--context arg无法识别时,我不明白为什么。
docker-compose --context remote build
答案 0 :(得分:1)
要解决此问题,docker-compose版本应至少为1.26.0
。